JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8771
  • Score
    100M100P100Q137694F
  • License MIT

An Extensive JavaScript Standard Library.

Package Exports

  • @opentf/std

Readme

 OPEN TECH FOUNDATION

JavaScript Standard Library

Build

An Extensive JavaScript Standard Library.

Features

  • Simple API
  • Practical Default Options
  • Includes Async Utils
  • TypeScript Support
  • ESM

Installation

npm install @opentf/std
yarn add @opentf/std
pnpm add @opentf/std
bun add @opentf/std

Usage

import {
  isNum,
  pascalCase,
  sort,
  clone,
  isEql,
  isEqlArr,
  sleep,
} from '@opentf/std';

isNum(NaN); //=> false

pascalCase('pascal case'); //=> PascalCase

sort([1, 10, 21, 2], 'desc'); //=> [ 21, 10, 2, 1 ]

const obj = {
  a: 1,
  b: 'abc',
  c: new Map([['key', 'val']]),
};
clone(obj); // It returns deeply cloned value.

const mapA = new Map([
  ['a', 1],
  ['b', 2],
]);
const mapB = new Map([
  ['b', 2],
  ['a', 1],
]);
isEql(mapA, mapB); //=> false

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

await sleep(1000); // It suspends the exection for 1 second.

API

Array

Async

Maths

Number

Function

Colors

Assert

Object

String

Types

Benchmarks

Some benchmark outputs are shown here for reference.

[!IMPORTANT]
Our priorities are reliability and accuracy rather than performance.

clone:
┌───┬──────────────────────────┬─────────┬────────────────────┬────────┬─────────┐
│   │ Task Name                │ ops/sec │ Average Time (ns)  │ Margin │ Samples │
├───┼──────────────────────────┼─────────┼────────────────────┼────────┼─────────┤
│ 0 │ structuredClone (Native)276,8243612.3959469709525 │ ±1.29% │ 27683   │
│ 1 │ _.cloneDeep (Lodash)216,9654609.032953864744  │ ±2.41% │ 21697   │
│ 2 │ R.clone (ramda)174,5675728.439422580611  │ ±1.92% │ 17457   │
│ 3 │ R2.clone (remeda)310,2683223.0154703960834 │ ±2.40% │ 31027   │
│ 4 │ cloneDeep (clone-deep)468,9082132.611673882092  │ ±1.70% │ 46891   │
│ 5 │ copy (fast-copy)486,1792056.852050680814  │ ±1.91% │ 48618   │
│ 6 │ clone                    │ 535,3021868.1028376072306 │ ±2.07% │ 53531   │
└───┴──────────────────────────┴─────────┴────────────────────┴────────┴─────────┘
*Note:
    - Here the lodash does not support errors, sparse arrays & objects in map keys.

    - Here the ramda & remeda does not support cloning Map & Set.

    - The fast-copy does not clone objects within Map, buffers in TypedArray, sparse arrays.

    - The clone-deep does not handle circular refs, does not clone objects within map,
    sparse arrays, internal refs within the object, TypedArray buffers & DataView.

sortBy:
┌───┬────────────────────┬───────────┬───────────────────┬────────┬─────────┐
│   │ Task Name          │ ops/sec   │ Average Time (ns) │ Margin │ Samples │
├───┼────────────────────┼───────────┼───────────────────┼────────┼─────────┤
│ 0 │ _.orderBy (Lodash)1,231,295 │ 812.1529684071648 │ ±3.09% │ 123130  │
│ 1 │ R.sortWith (Ramda)1,279,200 │ 781.7380570822326 │ ±2.27% │ 127921  │
│ 2 │ R2.sortBy (Remeda)1,419,707 │ 704.3703291518029 │ ±2.81% │ 141971  │
│ 3sort (Moderndash)2,697,568 │ 370.7042634668106 │ ±1.82% │ 269757  │
│ 4 │ sortBy             │ 2,728,366 │ 366.5196435965459 │ ±2.19% │ 272837  │
└───┴────────────────────┴───────────┴───────────────────┴────────┴─────────┘

*Note: Here the Moderndash does not support passing object prop as string.

isEql:
┌───┬─────────────────────────────────────┬─────────┬────────────────────┬────────┬─────────┐
│   │ Task Name                           │ ops/sec │ Average Time (ns)  │ Margin │ Samples │
├───┼─────────────────────────────────────┼─────────┼────────────────────┼────────┼─────────┤
│ 0 │ deepStrictEqual (Native)950,6861051.871609041841  │ ±0.24% │ 95069   │
│ 1 │ fastDeepEqual (fast-deep-equal/es6)652,6111532.3058134904193 │ ±1.49% │ 65262   │
│ 2 │ dequal                              │ 120,7918278.7573675501    │ ±0.74% │ 12080   │
│ 3 │ _.isEqual (Lodash)152,0756575.660376117521  │ ±2.02% │ 15208   │
│ 4 │ R.equals (Ramda)51,49619418.976504855284 │ ±1.70% │ 5150    │
│ 5 │ isEql                               │ 104,3559582.655710998957  │ ±1.13% │ 10436   │
└───┴─────────────────────────────────────┴─────────┴────────────────────┴────────┴─────────┘

*Note:

- The native util `deepStrictEqual` not available in browsers, does not check `Map` ordering & same invalid dates.
- The `fast-deep-equal/es6` does not support cyclic refs, Map ordering check, invalid dates, symbols, objects values in Set & TypedArrays.
- The lodash `isEqual` does not check `Map` ordering & object values in `Set`.
- The ramda `equals` does not check `Map` ordering & symbols.
- The dequal does not support cyclic refs, Map ordering, symbols & same invalid dates.

Running benchmarks

$ bun run build
$ bun benchmark.js

License

Copyright (c) Thanga Ganapathy (MIT License).