import { ALL_WEEKDAYS , WeekdayStr } from './weekday' ; export const isPresent = function < T > ( value ? ) : value is T { return value !== null && value !== undefined ; } ; export const isNumber = function ( value ? ) : value is number { return typeof value === 'number' ; } ; export const isWeekdayStr = function ( value ? ) : value is WeekdayStr { return ALL_WEEKDAYS . indexOf ( value ) >= 0 ; } ; export const isArray = Array . isArray ; /**
 * Simplified version of python's range()
 */ export const range = function ( start , end = start ) : number [ ] { if ( arguments . length === 1 ) { end = start ; start = 0 ; } const rang = [ ] ; for ( let i = start ; i < end ; i ++ ) rang . push ( i ) ; return rang ; } ; export const clone = function < T > ( array ) : T [ ] { return ( [ ] as T [ ] ) . concat ( array ) ; } ; export const repeat = function < T > ( value , times ) : ( T | T [ ] ) [ ] { let i = 0 ; const array = [ ] ; if ( isArray ( value ) ) { for ( ; i < times ; i ++ ) array [ i ] = ( [ ] as T [ ] ) . concat ( value ) ; } else { for ( ; i < times ; i ++ ) array [ i ] = value ; } return array ; } ; export const toArray = function < T > ( item ) : T [ ] { if ( isArray ( item ) ) { return item ; } return [ item ] ; } ; export function padStart ( item , targetLength , padString = ' ' ) { const str = String ( item ) ; targetLength = targetLength >> 0 ; if ( str . length > targetLength ) { return String ( str ) ; } targetLength = targetLength - str . length ; if ( targetLength > padString . length ) { padString += repeat ( padString , targetLength / padString . length ) ; } return padString . slice ( 0 , targetLength ) + String ( str ) ; } /**
 * Python like split
 */ export const split = function ( str , sep , num ) { const splits = str . split ( sep ) ; return num ? splits . slice ( 0 , num ) . concat ( [ splits . slice ( num ) . join ( sep ) ] ) : splits ; } ; param { number } a param { number } b return { number } export const pymod = function ( a , b ) { const r = a % b ; return r * b < 0 ? r + b : r ; } ; see export const divmod = function ( a , b ) { return { div : Math . floor ( a / b ) , mod : pymod ( a , b ) } ; } ; export const empty = function < T > ( obj ) { return ! isPresent ( obj ) || obj . length === 0 ; } ; return { Boolean } export const notEmpty = function < T > ( obj ) : obj is T [ ] { return ! empty ( obj ) ; } ; /**
 * Return true if a value is in an array
 */ export const includes = function < T > ( arr , val ) { return notEmpty ( arr ) && arr . indexOf ( val ) !== - 1 ; } ;