Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@easy-ds-bot/utils

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@easy-ds-bot/utils

Tiny TypeScript utils: wait(), arrayFromIterator(), chanceRandom(), formatNumber(), equal(), quickTextCompare() and more

Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
13
8.33%
Maintainers
1
Weekly downloads
 
Created
Source

Tiny TypeScript utils: wait(), arrayFromIterator(), chanceRandom(), equal() and more

API

Synchronous:

  • formatNumber(x: number): string
  • reportMemory(): void
  • random(min: number, max: number): number
  • arrRandom(arr: any[]): any
  • chanceRandom(elements: { [key: string]: number }): string
  • equal(v1: any, v2: any): boolean
  • quickTextCompare(text1: string, text2: string): boolean
  • includesAll(arr: any[], values: any[]): boolean
  • arrayFromIterator(iterator: IterableIterator<any>): any[]

Promises:

  • wait(time_ms: number): Promise<void>

Requirements

  • NodeJS, recommended v18 or newer

Setup

  • Install utils via npm:
npm i @easy-ds-bot/utils
  • Use it in your project:
// file.js, type: CJS
const { random, arrRandom } = require("@easy-ds-bot/utils");
let colors = ["red", "green", "blue"];
console.log(`Random int: ${random(1, 100)}, random color: ${arrRandom(colors)}`);
//> Random int: 32, random color: blue
//...it is one of 300 variants

...or:

// file.js, type: ESM
import { random, arrRandom } from "@easy-ds-bot/utils";
let colors = ["red", "green", "blue"];
console.log(`Random int: ${random(1, 100)}, random color: ${arrRandom(colors)}`);
//> Random int: 32, random color: blue
//...it is one of 300 variants

Benchmark

formatNumber(10num): x 2,148,840 ops/sec ±2.24% (88 runs sampled)
includesAll(5elem, 5elem): x 27,266,638 ops/sec ±1.76% (93 runs sampled)
await wait(1) x 763,328 ops/sec ±3.00% (79 runs sampled)
arrayFromIterator(5elem): 
random(1, 100) x 94,517,357 ops/sec ±0.92% (87 runs sampled)
arrRandom(5elem) x 95,086,408 ops/sec ±0.52% (94 runs sampled)
chanceRandom(5elem) x 2,063,074 ops/sec ±1.68% (93 runs sampled)
equal(str5char) x 198,447,672 ops/sec ±0.21% (93 runs sampled)
equal(arr5elem) x 202,415,487 ops/sec ±0.17% (95 runs sampled)
equal(obj5elem) x 6,218,884 ops/sec ±0.39% (97 runs sampled)
quickTextCompare(5word) x 1,142,553 ops/sec ±0.22% (97 runs sampled)
quickTextCompare(500word) x 26,003 ops/sec ±0.24% (95 runs sampled)
quickTextCompare(50_000word) x 224 ops/sec ±0.66% (82 runs sampled)

Source (git)

Issues (git)

Keywords

typescript

FAQs

Package last updated on 27 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts