1.0.1 • Published 8 months ago

@focme/rsk-util v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

@focme/rsk-util

a tool lib for rsk-template

functions

is

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

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 value end

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

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

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

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

optionvalueexample(984224415)
SSSSduration"984224415"
SSSmilliseconds"415"
SSfull seconds"984224"
ssseconds"44"
MMfull minutes"16403"
mmminutes"23"
HHfull hours"273"
hhhours"9"
dddays"11"

createDater

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

optionvalueexample(1695019785071)
YYYYFour-digit year"2023"
YYTwo-digit year"23"
MMMMThe full month name"September"
MMMThe abbreviated month name"Sep"
MMThe month, 2-digits"09"
MThe month, beginning at 1"9"
DDThe day of the month, 2-digits"18"
DThe day of the month"18"
dddThe name of the day of the week"Monday"
ddThe short name of the day of the week"Mon"
dThe day of the week, with Sunday as 0"1"
HHThe hour, 2-digits"14"
HThe hour"14"
hhThe hour, 12-hour clock, 2-digits"02"
hThe hour, 12-hour clock"2"
mmThe minute, 2-digits"49"
mThe minute"49"
SSSThe millisecond, 3-digits"071"
ssThe second, 2-digits"45"
sThe second"45"
A"PM"
a"pm"
ZZThe offset from UTC, ±HHmm"+0800"
ZThe offset from UTC, ±HH:mm"+08:00"
1.0.1

8 months ago

1.0.0-test-1

8 months ago