import wiki from "." ; import { pageError } from "./errors" ; import { MSGS } from "./messages" ; export function isString ( title ) { return isNaN ( title ) ; } export async function setTitleForPage ( title ) { { const searchResult = await wiki . search ( title , { limit : 1 , suggestion : true } ) ; if ( ! searchResult . suggestion && searchResult . results . length == 0 ) { throw new pageError ( `${ MSGS . PAGE_NOT_SUGGEST }${ title }` ) ; } title = searchResult . suggestion || title ; return title ; } } export function setPageIdOrTitleParam ( params , title ) { if ( isString ( title ) ) { params . titles = title ; } else { params . pageids = title ; } return params ; } export function setPageId ( params , results ) { let pageId ; if ( params . pageIds ) { pageId = params . pageIds ; } else { pageId = Object . keys ( results . query . pages ) [ 0 ] ; } return pageId ; } export function getCurrentMonth ( ) { const date = new Date ( ) ; const month = date . getMonth ( ) ; return ( month + 1 ) ; } export function getCurrentDay ( ) { const date = new Date ( ) ; const day = date . getDate ( ) ; return day ; }