import { padLeft } from "@thi.ng/strings/pad-left" ; import { percent as $percent } from "@thi.ng/strings/percent" ; import { maybeParseFloat , maybeParseInt } from "@thi.ng/strings/parse" ; import type { CellTransform } from "./api.js" ; param x export const upper = ( x ) => x . toUpperCase ( ) ; param x export const lower = ( x ) => x . toLowerCase ( ) ; param defaultVal export const float = ( defaultVal = 0 ) : CellTransform => ( x ) => maybeParseFloat ( x , defaultVal ) ; param defaultVal export const int = ( defaultVal = 0 ) : CellTransform => ( x ) => maybeParseInt ( x , defaultVal , 10 ) ; param defaultVal export const hex = ( defaultVal = 0 ) : CellTransform => ( x ) => maybeParseInt ( x , defaultVal , 16 ) ; export const percent = ( x ) => maybeParseFloat ( x ) * 0.01 ; param defaultVal export const epoch = ( defaultVal = 0 ) : CellTransform => ( x ) => { const res = Date . parse ( x ) ; return isNaN ( res ) ? defaultVal : res ; } ; param defaultVal export const date = ( defaultVal ? ) : CellTransform => ( x ) => { const epoch = Date . parse ( x ) ; if ( isNaN ( epoch ) ) return defaultVal ; const res = new Date ( ) ; res . setTime ( epoch ) ; return res ; } ; param x export const url = ( x ) => new URL ( x ) ; export const zeroPad = ( digits ) => padLeft ( digits , "0" ) ; export const formatFloat = ( prec = 2 ) => ( x ) => x . toFixed ( prec ) ; /**
 * Higher order cell value formatter. Takes normalized values and formats them
 * as percentage with given `precision` (number of fractional digits).
 */ export const formatPercent = $percent ;