import { encode } from "he" ; import { times } from "./Array" ; import { Maybe } from "./Maybe" ; export function isString ( o ) { return typeof o === "string" ; } const spaces = times ( 10 , ( i ) => times ( i , ( ) => " " ) . join ( "" ) ) ; const zeroes = times ( 10 , ( i ) => times ( i , ( ) => "0" ) . join ( "" ) ) ; export function blank ( s ) { return s == null || String ( s ) . trim ( ) . length === 0 ; } export function notBlank ( s ) { return ! blank ( s ) ; } function padding ( padChar , count ) { if ( count <= 0 ) return "" ; return ( padChar === "0" ? zeroes : spaces ) [ Math . floor ( count ) ] ! ; } export function toS ( s ) { return s == null ? "" : String ( s ) ; } export function leftPad ( i , minLen , padChar ) { if ( i == null || isNaN ( i ) ) i = 0 ; if ( i < 0 ) { return "-" + leftPad ( - i , minLen - 1 , padChar ) ; } else { const s = String ( i ) ; return padding ( padChar , minLen - s . length ) + s ; } } export function pad2 ( ... numbers ) { return numbers . map ( ( i ) => leftPad ( i , 2 , "0" ) ) ; } export function pad3 ( ... numbers ) { return numbers . map ( ( i ) => leftPad ( i , 3 , "0" ) ) ; } /**
 * NOTE: case insensitive
 */ export function stripPrefix ( s , prefix ) { return toS ( s ) . toLowerCase ( ) . startsWith ( prefix . toLowerCase ( ) ) ? s . slice ( prefix . length ) : s ; } export function stripSuffix ( s , suffix ) { const str = toS ( s ) ; return str . endsWith ( suffix ) ? str . slice ( 0 , - suffix . length ) : str ; } export function htmlEncode ( s ) { return encode ( s , { decimal : true } ) . replace ( /\s/g , ( m ) => m [ 0 ] === " " ? " " : `&#${ m [ 0 ] ! . charCodeAt ( 0 ) };` ) ; }