Helpers (v3+)
Optional modules beyond types, regex, and validate. Tree-shake by importing only the subpaths you need: helping-js/core/<module>.
Module docs (samples on each page)
| Doc page | npm import |
|---|---|
| Number | helping-js/core/number |
| String | helping-js/core/string |
| Value | helping-js/core/value |
| Array | helping-js/core/array |
| Object | helping-js/core/object |
| Function | helping-js/core/function |
| Async | helping-js/core/async |
| URL | helping-js/core/url |
| Date | helping-js/core/date |
| Advanced | helping-js/core/advanced |
| Tree | helping-js/core/tree |
| DOM | helping-js/core/dom (browser) |
Module overview (source)
| Subpath | What it gives you |
|---|---|
| core/number | randInt, randChoice, between, notLessThan, notGreaterThan, strPad |
| core/string | camelCase, kebabCase, snakeCase, studlyCase, titleCase, camelToWords, randString, reverseString |
| core/value | isEmptyValue — treats null, undefined, '', [], {}, false, 0, NaN as empty |
| core/array | arrayRemove, arrayDiff, splitArray, groupArray, arrayDistinct, arrayFlat, toArrayIfNot, … |
| core/object | dotGet, dotSet (blocks __proto__ / constructor / prototype paths), objectOnly, objectExcept, cloneObject, … |
| core/function | resolveValueOrGetter, bindContext, mapObjectTree, composition helpers |
| core/async | debounceTrailing, debounceImmediate, retry, promiseTimeout, executePromiseGetters, … |
| core/url | pathJoin (Node-safe), getUrlParam (optional URL string or current page in the browser) |
| core/date | cloneDate, addDate, getMonthStart / getMonthEnd, getCalendar, parseISO, isIsoFormat |
| core/advanced | binarySearch, Cache, ArrayKeyMap, attachCache, easeInOutQuad, windowLoaded, … |
| core/tree | walkTreeData, TreeData with safe clone() |
| core/dom | Browser only — on, off, addClass, viewportPositionToFixed, … Do not import in pure Node SSR bundles. |
Naming conflicts with other libraries: core/types keeps existing semantics (isNumber, isNumeric, …). See HELPER_INVENTORY.md.
Minimal examples
import { strPad, between } from 'helping-js/core/number'
import { kebabCase } from 'helping-js/core/string'
import { dotSet, dotGet } from 'helping-js/core/object'
import { isEmptyValue } from 'helping-js/core/value'
const state = {}
dotSet(state, 'user.profile.id', 42)
console.log(kebabCase('FooBar')) // 'foo-bar'
console.log(strPad('7', 3, '0')) // '007'
console.log(between(150, 0, 100)) // 100
console.log(isEmptyValue(state.user)) // false
Vue 3 (Composition API)
Debounce user input, format labels, and read nested config with dotGet:
<script setup>
import { ref, watch } from 'vue'
import { debounceTrailing } from 'helping-js/core/async'
import { titleCase } from 'helping-js/core/string'
import { dotGet } from 'helping-js/core/object'
const props = defineProps({ config: Object })
const query = ref('')
const heading = ref('')
const runSearch = debounceTrailing((q) => {
heading.value = titleCase(q.trim() || 'search')
// e.g. call API with q
}, 300)
watch(query, (v) => runSearch(v))
const apiBase = () => dotGet(props.config, 'api.baseUrl')
</script>
React (hooks)
Memoize derived data with array/object helpers:
import { useMemo, useState } from 'react'
import { arrayDistinct, splitArray } from 'helping-js/core/array'
import { objectOnly } from 'helping-js/core/object'
export function TagList({ items }) {
const [page, setPage] = useState(0)
const unique = useMemo(() => arrayDistinct(items), [items])
const pages = useMemo(() => splitArray(unique, 10), [unique])
const slice = pages[page] ?? []
return (
<ul>
{slice.map((id) => (
<li key={id}>{id}</li>
))}
</ul>
)
}
// Pick a subset of props for a child
export function passThemeProps(full) {
return objectOnly(full, ['mode', 'density'])
}
Express (Node)
Join path segments safely and reuse type helpers in middleware:
const express = require('express')
const path = require('path')
const { pathJoin } = require('helping-js/core/url')
const { isString } = require('helping-js/core/types')
const app = express()
const publicDir = pathJoin(__dirname, 'public')
app.use(express.static(publicDir))
app.get('/health', (req, res) => {
const tag = req.query.tag
if (tag != null && !isString(tag)) {
return res.status(400).json({ error: 'tag must be a string' })
}
res.json({ ok: true })
})
pathJoin normalizes slashes for URL-like segments; for filesystem paths you can still use path.join from Node — use whichever fits the use case.
Browser-only (core/dom)
Import only in client code (Vite i, Next.js 'use client', or Vue client components):
import { on, addClass } from 'helping-js/core/dom'
const el = document.querySelector('#app')
if (el) {
addClass(el, 'is-ready')
const un = on(el, 'click', () => {
console.log('clicked')
un()
})
}
See also
- Usage — install and ESM/CJS
- Types — type checkers
- Form validation —
validate()and preset - CHANGELOG — v3 helper modules
