Skip to content

About

simple utils for javascript

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Repository files navigation


helping-js — JavaScript utility library npm package logo

helping-js

Zero-dependency JavaScript utilities for Node and browsers — types, regex, validation, TypeScript, and optional helper modules.

version MIT license downloads
gzip size no dependencies CI


📚 Document ・ 🔎 Demos ・ 🔬 Playground ・ 📋 Changelog

Documentation: helping-js.netlify.app (usage, helpers, form validation, regex). v3 adds optional helper modules (helping-js/core/number, core/string, core/array, core/object, core/async, core/date, …). See CHANGELOG.md and docs/HELPER_INVENTORY.md.

Helper modules (subpath imports)

Export path Contents (summary)
helping-js/core/number randInt, randChoice, between, strPad, …
helping-js/core/string camelCase, kebabCase, randString, …
helping-js/core/value isEmptyValue
helping-js/core/array arrayDiff, splitArray, arrayDistinct, …
helping-js/core/object dotGet, dotSet, objectOnly, …
helping-js/core/function resolveValueOrGetter, mapObjectTree, …
helping-js/core/async debounceTrailing, debounceImmediate, retry, …
helping-js/core/url pathJoin, getUrlParam
helping-js/core/date parseISO, getCalendar, addDate, …
helping-js/core/advanced binarySearch, Cache, windowLoaded, …
helping-js/core/tree TreeData, walkTreeData
helping-js/core/dom DOM helpers (prefer not in Node-only SSR)

Quick examples

import { strPad, between } from 'helping-js/core/number'
import { kebabCase, titleCase } from 'helping-js/core/string'
import { dotSet, dotGet } from 'helping-js/core/object'
import { debounceTrailing } from 'helping-js/core/async'
import { pathJoin } from 'helping-js/core/url'

dotSet({}, 'meta.version', 1)
console.log(kebabCase('UserName'), strPad('3', 2, '0')) // 'user-name', '03'

const search = debounceTrailing((q) => console.log(titleCase(q)), 250)
search('hello world')

console.log(pathJoin('/api', 'v1', 'users')) // '/api/v1/users'

Vue 3 — debounced input and nested config:

import { debounceTrailing } from 'helping-js/core/async'
import { dotGet } from 'helping-js/core/object'

const onInput = debounceTrailing((e) => {
  const q = e.target.value
  // search(q)
}, 300)
const base = dotGet(config, 'api.baseUrl') // e.g. from props or Pinia

React — distinct IDs and pagination chunks:

import { arrayDistinct, splitArray } from 'helping-js/core/array'
const unique = arrayDistinct(ids)
const pages = splitArray(unique, 20)

Express — path segments and numeric query checks:

const { pathJoin } = require('helping-js/core/url')
const { isNumeric } = require('helping-js/core/types')

const uploadRoot = pathJoin(__dirname, 'public', 'uploads')

app.get('/items', (req, res) => {
  const page = req.query.page
  if (page != null && !isNumeric(page)) {
    return res.status(400).json({ error: 'page must be numeric' })
  }
  res.json({ uploadRoot })
})

Full walkthrough: docs/docs/helpers/index.md. The doc site lists one page per module under Helpers (e.g. /helpers/number/, /helpers/async/) with API tables and samples.

Dependencies

  • No need Dependency

Installation

npm install helping-js --save
yarn add helping-js

Usage

  1. You can import in your js file es6 (modules,vue,react,...)
import { isString } from 'helping-js/core/types'

console.log(isString('test')) // true
console.log(isString(true)) // false
  1. You can import in your js file es5 (nodejs)
var { isString } = require('helping-js/core/types')

console.log(isString('test')) // true
console.log(isString(true)) // false
  1. You can use from CDN (ESM only). Pin a version for production: https://unpkg.com/helping-js@3/core/types.js
import { isString } from 'https://unpkg.com/helping-js/core/types.js'

console.log(isString('test')) // true
console.log(isString(true)) // false
  1. TypeScript: the package includes .d.ts files; types work automatically when you import from helping-js/core/*.

Validate forms

Lightweight validation without validator.js: use validate(obj, rules) with RegExp or predicate functions.

import { validate, RX_EMAIL, isNumber } from 'helping-js/preset/form';

const result = validate(
  { email: 'user@example.com', age: 25 },
  { email: RX_EMAIL, age: isNumber }
);
// result.valid === true, result.errors === {}

// Or import only validate and use your own rules:
import { validate } from 'helping-js/core/validate';
import { RX_EMAIL } from 'helping-js/core/regex';

Rules can be a RegExp (tests String(value)) or a function (value) => boolean. Returns { valid: true, errors: {} } or { valid: false, errors: { field: false, ... } }.

Usage in your project

No extra config; install and import.

  • Node (CJS): const { isString } = require('helping-js/core/types');
  • Node (ESM): import { isString } from 'helping-js/core/types'; (use "type": "module" in package.json or .mjs extension).
  • Vite: import { isString } from 'helping-js/core/types';
  • Next.js: import { isString } from 'helping-js/core/types'; (client or server).
  • Create React App: import { isString } from 'helping-js/core/types';

Regex Usage

You can access all regex patterns from the helping-js/core/regex module. (More Than 50 Patterns)

Example usage:

import { RX_HASH } from "helping-js/core/regex";
const regex = RX_HASH;
const str = '#test';
console.log(regex.test(str)); // Output: true

About

simple utils for javascript

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages