a tool lib for rsk-template
is.nil
param
- target:
any
returns boolean
determine target
is undefined
or null
import { is } from "@focme/rsk-util"
is.nil(undefined) // true
is.nil(null) // true
is.nil("") // false
is.nil(0) // false
is.nil(true) // false
is.nil({}) // false
is.nil([]) // false
is.nilEmpty
param
- target:
any
returns boolean
determine target
is nil
or empty string
import { is } from "@focme/rsk-util"
is.nilEmpty(undefined) // true
is.nilEmpty(null) // true
is.nilEmpty("") // true
is.nil(0) // false
is.nil(true) // false
is.nil({}) // false
is.nil([]) // false
fill
param
- option:
{ target, length, item, position }
target: string
target string
length: number
length of the result
item: string
the item filled into target
position: start | end | around
filling position default valueend
returns string
import { fill } from "@focme/rsk-util"
fill() // ""
fill({ length: 10 }) // " "
fill({ length: 10, item: "1" }) // "1111111111"
fill({ target: "6", length: 2, item: "0" }) // "60"
fill({ target: "6", length: 2, item: "0", position: "start" }) // "06"
createCurrent
param
- init:
any
returns { current: any }
a copy of React.useRef
hook
import { createCurrent } from "@focme/rsk-util"
const current = createCurrent(0)
console.log(current) // { current: 0 }
createJoin
param
- separator:
string
returns (...arg[]: any[]) => string
a Array.prototyp.join.call
function
const { createJoin } from "@focme/rsk-util"
const join = createJoin()
join([1, 3, 5, () => 7]) // `1357`
join("-") // `1-3-5-7`
const { createJoin } from "@focme/rsk-util"
const join = createJoin("-")
join([1, 3, 5, () => 7]) // `1-3-5-7`
createJoin.from
param
- ...arg[]:
any[]
returns (separator: string) => string
a Array.prototyp.join.call
function
const { createJoin } from "@focme/rsk-util"
const join = createJoin.from([1, 3, 5, () => 7])
join() // `1357`
join("-") // `1-3-5-7`
createTimer
returns { check, record, records, format }
> check()
add a record
> record(index: number)
get a record
> records()
get all records
> format(template: string, index?: number)
format a record to string
record durations
const createTimer from "@focme/rsk-util"
const timer = createTimer()
timer.record() // 0
setTimeout(() => {
timer.check()
timer.record() // may be 10
timer.record(-1) // may be 10
timer.record(0) // 0
timer.records() // may be [0, 10]
timer.format("ss\\s") // may be 10s
timer.format("ss\\s", 0) // 0s
}, 10)
format option
option | value | example(984224415) |
---|---|---|
SSSS | duration | "984224415" |
SSS | milliseconds | "415" |
SS | full seconds | "984224" |
ss | seconds | "44" |
MM | full minutes | "16403" |
mm | minutes | "23" |
HH | full hours | "273" |
hh | hours | "9" |
dd | days | "11" |
createDater
param
- date:
Date
returns { current, format }
const { createDater } from "@focme/rsk-util"
const dater = createDater(new Date(1695019785071))
console.log(dater.current) // { YYYY, YY, ... }
dater.format("YYYY") // 2023
dater.format("YYYY-MM-DD HH:mm:ss") // "2023-09-18 14:49:45"
format option
option | value | example(1695019785071) |
---|---|---|
YYYY | Four-digit year | "2023" |
YY | Two-digit year | "23" |
MMMM | The full month name | "September" |
MMM | The abbreviated month name | "Sep" |
MM | The month, 2-digits | "09" |
M | The month, beginning at 1 | "9" |
DD | The day of the month, 2-digits | "18" |
D | The day of the month | "18" |
ddd | The name of the day of the week | "Monday" |
dd | The short name of the day of the week | "Mon" |
d | The day of the week, with Sunday as 0 | "1" |
HH | The hour, 2-digits | "14" |
H | The hour | "14" |
hh | The hour, 12-hour clock, 2-digits | "02" |
h | The hour, 12-hour clock | "2" |
mm | The minute, 2-digits | "49" |
m | The minute | "49" |
SSS | The millisecond, 3-digits | "071" |
ss | The second, 2-digits | "45" |
s | The second | "45" |
A | "PM" | |
a | "pm" | |
ZZ | The offset from UTC, ±HHmm | "+0800" |
Z | The offset from UTC, ±HH:mm | "+08:00" |