waelio-utils

Helper Utils often used in websites
8,166 1
Install
npm install waelio-utils
Latest Version:5.0.9
Older releases:2
License:MIT
Last Updated:May 25, 2026
Links: GitHub  ·  npm
Maintainer: waelio

Waelio Utilities

Tests NPM version NPM monthly downloads NPM total downloads Join the chat at https://discord.gg/tBZ2Fmdb7E Edit on CodeSandbox TypeScript

The WaelioUtils exported as a Javascript modules

docs

  1. Recently Added/Updated
  2. _reactive
    Reactive object with property tracking
    _trickle
    Reduces numbers array in stages
    _reParseString
    Deep clone via JSON parse/stringify

  3. Strings
  4. _jsonToQueryString
    JSON object → URL query string
    _queryStringToJson
    URL query string → JSON object
    _resetString
    URL-decodes an encoded string
    _snakeToCamel
    snake_case → camelCase
    _camelToSnake
    camelCase → snake_case or kebab-case
    _toBase64
    Encodes a string to Base64
    _generateId
    Generates a random ID string
    _sniffId
    Extracts id/_id/Id from an object
    _a_or_an
    Returns "a" or "an" for a word
    _encrypt
    Encrypts any value with a salt
    _decrypt
    Decrypts an encrypted value

  5. Arrays
  6. _hideRandom
    Masks random indexes in an array
    _rotateArray
    Rotates a 2D array 90° clockwise
    _equals
    Deep equality check for arrays
    _repeat
    Runs a function N times
    _chunk
    Splits array into chunks of size N
    _rotate
    Rotates a matrix 90° clockwise
    _rotateCounterClockwise
    Rotates a matrix 90° counter-clockwise
    _transpose
    Swaps rows and columns of a matrix
    _encrypt
    Encrypts any value with a salt
    _decrypt
    Decrypts an encrypted value

  7. Objects
  8. _sniffId
    Extracts id/_id/Id from an object
    _cleanResponse
    Unwraps paginated API response data
    _deepClone
    Deep clones objects, arrays, Dates
    _get
    Safely reads nested object/array data
    _omit
    Creates object excluding specified keys
    _pick
    Creates object with only specified keys
    _encrypt
    Encrypts any value with a salt
    _decrypt
    Decrypts an encrypted value

  9. Type Checkers / Validators
  10. _isArray
    Checks if value is an Array
    _isFunction
    Checks if value is a Function
    _isNumber
    Checks if value is a Number
    _isObject
    Checks if value is an Object
    _isString
    Checks if value is a String
    _isValid
    Checks if value is array, object, string, or number

  11. Math
  12. _fibonacci
    Returns the nth Fibonacci number
    _fibonacciSequence
    Returns Fibonacci sequence up to nth
    _factorial
    Returns factorial of a non-negative integer
    _isPrime
    Checks if a number is prime
    _sieveOfEratosthenes
    All primes up to a given limit
    _sumOf
    Sums an array of numbers

  13. Other
  14. _calculateClockDrift
    Calculates JWT token clock drift
    _notifyMe
    Sends a PWA browser notification
    _to
    Wraps a promise → [error, result]
    _a_or_an
    Returns "a" or "an" for a word

Installation

In terminal: Pick your flavor, types included

npm i -S waelio-utils
pnpm add -S waelio-utils
yarn add -S waelio-utils

OR

In browser:

<script src="https://unpkg.com/waelio-utils@latest/lib/waelioUtils.js"></script>

Or in terminal add indvidual packagees

// ES6
import { _snakeToCamel, _notifyMe } from 'waelio-utils';

// NodeJS
const { _snakeToCamel, _notifyMe } = require('waelio-utils');

jsonToQueryString

Function that converts a JSON to URL Query String @param {} JSON payload Returns String

Example: In your .js or .ts file
import { _jsonToQueryString } from 'waelio-utils';
const payload = { first: 'John', last: 'Smith' };
const Result = jsonToQueryString(payload);
Result
'name=John&last=smith';

Back to TOP

queryStringToJson

Function that converts a URL Query String to JSON @param payload Type @param {string} as String Returns JSON || Object

Example: In your .js or .ts file
import { _queryStringToJson } from 'waelio-utils';
const query = (name = 'John&last=smith');
const Result = queryStringToJson(query);
Result
{ first: 'John', last: 'Smith' }

Back to TOP

resetString

import { _resetString } from 'waelio-utils';

const payload = 'https%3A%2F%2Fwaelio.com';
const Result = resetString(payload);

Result === 'https://waelio.com';

Back to TOP

snakeToCamel

Function that converts snake_case or snake-case to camelCase "snakeCase" @name snakeToCamel

@param {string} payload QueryString

Returns {string}

Example: In your .js or .ts file
import { _snakeToCamel } from 'waelio-utils';
const payload = 'north-west_meta';
const Result = snakeToCamel(payload);
Result
'northWestMeta';

Back to TOP

camelToSnake

Function that converts camelCase to snake_case or snake-case "snake-case"

@param {string} payload

@param {boolean} hyphenated controls the delimiter: true = "-" / false = "_"

Returns {string}

Example: In your .js or .ts file
import { _camelToSnake } from 'waelio-utils';
const payload = 'northWestMeta';
const Result = camelToSnake(payload);
Result 1- camelToSnake( payload )
'north_west_meta';
Result 2- camelToSnake( payload, true )
'north-west-meta';

Back to TOP

toBase64

Converts a string to Base64

Example: In your .js or .ts file
import { _toBase64 } from 'waelio-utils';
const payload = 'north-west_meta';
const Result = Base64(payload);
Result
'bm9ydGgtd2VzdF9tZXRh';

Back to TOP

reParseString

Simple object Standardization

OR object Deep Cloning <- Not best practice

Warning: Watchout for nulls, undefined, NaN and dates

Returns JSON.parse(JSON.stringify(payload))

Example: In your .js or .ts file
import { _reParseString } from 'waelio-utils';

// No magic here, use wisely

Back to TOP

generateId

Generate random string/id

@param {number} start 2 OPTIONAL

@param {number} len 9 OPTIONAL

Returns {string}

Example: In your .js or .ts file
import { _generateId } from 'waelio-utils';
const result = generateId();
Result: (random)
// result === '3uqi11wg9'

Back to TOP

calculateClockDrift

Calculates the clock drift between the current time and the issued-at time (IAT) of access/ID tokens. Useful for detecting token expiry and clock skew.

@param {number} iatAccessToken — IAT from the access token

@param {number} iatIdToken — IAT from the ID token

Returns {number} seconds of drift

Example: In your .ts file
import { _calculateClockDrift } from 'waelio-utils';

const drift = _calculateClockDrift(accessToken.iat, idToken.iat);
// drift === seconds between token issuance and now

Back to TOP

notifyMe

Send PWA Notifications to Site
Works only in Browser
@param {string} to send
Example: In your .js or .ts file
import { _notifyMe } from 'waelio-utils';
notifyMe('Hello World!');

Back to TOP

sniffid

Deconstruct id,Id,_Id,id from Object

Example:

var response = { _id: 1234, name: 'John' };
var newId = sniffId(response);
// newId === 1234

Back to TOP

hiderandom

Hide random array indexes

@params array
@params difficulty = 3
@params replacement = ''

Example:

import { _hideRandom } from 'waelio-utils';
const arr = [
  [1, 2, 3],
  [1, 2, 3],
  [1, 2, 3],
];
const test = _hideRandom(arr, 3);

/* random

  [1, 2, ""]
  ["", 2, ""]
  ["", "", 3]

*/

Back to TOP

rotatearray

Rotate array

import { _rotateArray } from 'waelio-utils';
const testArray = [
  [1, 2, 3],
  [1, 2, 3],
  [1, 2, 3],
];

const test1 = _rotateArray(testArray);
/* 
  [1, 1, 1],
  [2, 2, 2],
  [3, 3, 3]
*/

Back to TOP

repeat

Repeat function N times

Example

import { _repeat } from 'waelio-utils';
let counter = 0;
const f1 = () => counter++;

_repeat(5)(f1);

// counter === 5

Back to TOP

equals

Example

import { _equals } from 'waelio-utils';
const arr1 = [1, 2, 3, 4, 5];
const arr2 = [1, 2, 3, 4, 5];
const arr3 = [1, 2, 3, 4, 5, 6];

_equals(arr1, arr2); // true
_equals(arr1, arr3); // false

Back to TOP

cleanresponse

Example

import { _cleanResponse } from 'waelio-utils';

const demoRes = {
  total: 1,
  limit: 10,
  skip: 0,
  data: [
    {
      _id: '650937936xc8b143d8c575d2a',
      name: 'Some Data',
      user: '679363c6dc8b123d8c575d29',
      createdAt: '2021-05-06T06:14:09.209Z',
      updatedAt: '2021-05-06T06:14:09.209Z',
      __v: 0,
    },
  ],
};

const cleanRes = _cleanResponse(demoRes);
/* [ 
      {
        "_id": "650937936xc8b143d8c575d2a",
        "name": "Some Data",
        "user": "679363c6dc8b123d8c575d29",
        "createdAt": "2021-05-06T06:14:09.209Z",
        "updatedAt": "2021-05-06T06:14:09.209Z",
        "__v": 0
      }
    ]
  */

Back to TOP

to

Turn any function to Promise

[null, resolve][(reject, null)]; // resolve // reject

Example:

import { _to } from 'waelio-utils';
import axios from 'axios';
const testEndpoint = 'https://api.picmymenu.com/restaurants';
const response = await _to(axios(testEndpoint));
const [reject, resolve] = response;

expect(response).toBeTruthy(); // true
expect(resolve).toBeTruthy(); // true
expect(reject).not.toBeTruthy(); //true
expect(resolve.data.length).toBeTruthy(); //true

Back to TOP

a_or_an

Example

import { _a_or_an } from 'waelio-utils';
const payload1 = 'apple';
const payload2 = 'bananas';
const payload3 = 'orange';

a_or_an(payload1); // an
a_or_an(payload2); // a
a_or_an(payload3); // an

Back to TOP

encrypt

Possible payloads string, object & array , number

_encrypt: _encrypt(payload, salt?)

If salt is not provided it will revert to the string "salt" as the default salt.


decrypt

_decrypt: _decrypt(payload, salt)

If salt is not provided and asFunction is false it will revert to the string "salt" as the default salt


_decrypt: _decrypt(payload, salt?)

Example

import { _encrypt, _decrypt, _generateId, _equal } from 'waelio-utils';

const salt = generateId(); // "g9rlygzjd"
const payload1 = 'What ever you want';
const payload2 = { message: 'What ever you want' };

const encrypted1 = _encrypt(payload1);
const decrypted2 = _decrypt(encrypted1); // "What ever you want"

const encrypted2 = _encrypt(payload2, salt);
const decrypted3 = _decrypt(encrypted2, salt); // {"message":"What ever you want"}

// Test
const dblCheck = _equal(payload2, JSON.parse(decrypted2)); // true

Back to TOP

reactive

Makes an object reactive by tracking its properties using a watcher.

Example:

import { reactive, watcher } from 'waelio-utils';

const state = reactive({ count: 0 });

watcher(() => {
  console.log(`Count is: ${state.count}`);
}); // Automatically logs "Count is: 0"

state.count = 1; // Logs "Count is: 1"

Back to TOP

trickle

Trickle reduces an array of numbers in stages.

Example:

import { trickle_first_stage, trickle_second_stage } from 'waelio-utils';

const row = [19, 8, 92, 37, 46, 58, 6, 97, 78];
const stage1 = trickle_first_stage(row); // [119, 141, 181]
const stage2 = trickle_second_stage(stage1); // 441

Back to TOP

fibonacci

Calculates the nth number in the Fibonacci sequence.

Example:

import { fibonacci } from 'waelio-utils';

const result = fibonacci(6); // 8

Back to TOP

fibonacciSequence

Generates an array containing the Fibonacci sequence up to the nth position.

Example:

import { fibonacciSequence } from 'waelio-utils';

const result = fibonacciSequence(6); // [0, 1, 1, 2, 3, 5, 8]

Back to TOP

factorial

Calculates the factorial of a given non-negative integer.

Example:

import { factorial } from 'waelio-utils';

const result = factorial(5); // 120

Back to TOP

isPrime

Checks if a given number is a prime number.

Example:

import { isPrime } from 'waelio-utils';

const result = isPrime(7); // true
const result2 = isPrime(10); // false

Back to TOP

sieveOfEratosthenes

Uses the Sieve of Eratosthenes algorithm to find all prime numbers up to a given limit.

Example:

import { sieveOfEratosthenes } from 'waelio-utils';

const primes = sieveOfEratosthenes(10); // [2, 3, 5, 7]

Back to TOP

sumOf

Returns the sum of an array of numbers.

Example:

import { sumOf } from 'waelio-utils';

const result = sumOf([1, 2, 3, 4, 5]); // 15

Back to TOP

chunk

Creates an array of elements split into groups the length of size.

Example:

import { chunk } from 'waelio-utils';

chunk(['a', 'b', 'c', 'd'], 2); // => [['a', 'b'], ['c', 'd']]

Back to TOP

deepClone

Performs a deep clone of a value, handling objects, arrays, Dates, RegExps, and circular references.

Example:

import { deepClone } from 'waelio-utils';

const obj = { a: 1, b: { c: 2 } };
const cloned = deepClone(obj);

Back to TOP

get

Safely gets nested data depending on if it's an object or array.

Example:

import { get } from 'waelio-utils';

const data = { data: { inner: 'value' } };
const innerData = get(data);

Back to TOP

omit

Creates an object composed of the own and inherited enumerable property paths of an object that are not omitted.

Example:

import { omit } from 'waelio-utils';

const obj = { a: 1, b: 2, c: 3 };
const omitted = omit(obj, ['a', 'c']); // { b: 2 }

Back to TOP

pick

Creates an object composed of the picked object properties.

Example:

import { pick } from 'waelio-utils';

const obj = { a: 1, b: 2, c: 3 };
const picked = pick(obj, ['a', 'c']); // { a: 1, c: 3 }

Back to TOP

rotate

Rotates a 2D array (matrix) 90 degrees clockwise.

Example:

import { rotate } from 'waelio-utils';

const matrix = [
  [1, 2],
  [3, 4],
];
const rotated = rotate(matrix); // [[3, 1], [4, 2]]

Back to TOP

rotateCounterClockwise

Rotates a 2D array (matrix) 90 degrees counter-clockwise.

Example:

import { rotateCounterClockwise } from 'waelio-utils';

const matrix = [
  [1, 2],
  [3, 4],
];
const rotated = rotateCounterClockwise(matrix); // [[2, 4], [1, 3]]

Back to TOP

transpose

Transposes a 2D array (matrix), swapping rows and columns.

Example:

import { transpose } from 'waelio-utils';

const matrix = [
  [1, 2],
  [3, 4],
];
const transposed = transpose(matrix); // [[1, 3], [2, 4]]

Back to TOP

isArray

Checks if value is classified as an Array object.

Example:

import { isArray } from 'waelio-utils';

isArray([1, 2, 3]); // => true

Back to TOP

isFunction

Checks if value is classified as a Function object.

Example:

import { isFunction } from 'waelio-utils';

isFunction(() => {}); // => true

Back to TOP

isNumber

Checks if value is classified as a Number primitive or object.

Example:

import { isNumber } from 'waelio-utils';

isNumber(3); // => true

Back to TOP

isObject

Checks if value is the language type of Object.

Example:

import { isObject } from 'waelio-utils';

isObject({}); // => true

Back to TOP

isString

Checks if value is classified as a String primitive or object.

Example:

import { isString } from 'waelio-utils';

isString('abc'); // => true

Back to TOP

isValid

Verifies payload is an Array, Object, String, or Number.

Example:

import { isValid } from 'waelio-utils';

isValid({}); // => true
isValid(null); // => false

Back to TOP

https://waelio.com/packages/waelio-utils

Related Packages

@agnostico/browser-solidity-compiler

Solidity compiler that works in the browser

1,548 18
@framit/meta-pixel

Simple, framework agnostic and GDPR Compliance library to track data to Meta Pix...

15,362 5
@homedia/meta-pixel

Simple, framework agnostic and GDPR Compliance library to track data to Meta Pix...

1,961
@dlhsoft/ganttcharthyperlibrary

Gantt Chart library for JavaScript and TypeScript with Angular, React, and Vue e...

2,650 2
@therafiali/localstorage-utils

A comprehensive, general-purpose localStorage utility library for any JavaScript...

629 0

Version History

Version Released License
5.0.9 MIT
5.0.8 MIT
5.0.7 MIT
5.0.6 MIT
5.0.5 MIT
Pre-releases (7)
Version Released Vue License
2.0.11-beta.6 ^2.6.12 MIT
2.0.11-beta.5 ^2.6.12 MIT
2.0.11-beta.4 ^2.6.12 MIT
2.0.11-beta.3 ^2.6.12 MIT
2.0.11-beta.2 ^2.6.12 MIT