# @focme/rsk-util

> a tool lib for rsk-template

Latest version **2.0.1** (published 2025-01-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @focme/rsk-util
pnpm add @focme/rsk-util
yarn add @focme/rsk-util
bun add @focme/rsk-util
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2025-01-04 |
| First published | 2023-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 38.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | focme |
| Maintainers | rplss |

## Links

- npm: https://www.npmjs.com/package/@focme/rsk-util
- Repository: https://github.com/foc-me/rsk-util
- Homepage: https://github.com/foc-me/rsk-util#readme
- Issues: https://github.com/foc-me/rsk-util/issues
- npm.io page: https://npm.io/package/@focme/rsk-util

## Recent versions

- 2.0.1 (latest) — 2025-01-04
- 2.0.0 — 2025-01-02
- 1.0.3 — 2024-10-13
- 1.0.2 — 2024-07-26
- 1.0.1 — 2023-09-20
- 1.0.0-test-1 — 2023-09-20

## README

# @focme/rsk-util

a tool lib for rsk-template

## functions  

### is  

**`is.nil`**  
param  

* target: `any`  

returns `boolean`  

determine `target` is `undefined` or `null`

```javascript
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  

```javascript
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`  

```javascript
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  

```javascript
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  

```javascript
const { createJoin } from "@focme/rsk-util"

const join = createJoin()
join([1, 3, 5, () => 7]) // `1357`
join("-") // `1-3-5-7`
```

```javascript
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  

```javascript
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  

```javascript
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  

**`createDater`**  
param  

* date: `Date`  

returns `{ current, format }`  

```javascript
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"              |

---
_Source: https://npm.io/package/@focme/rsk-util · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
