npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

es-first-aid

v1.6.2

Published

The Fundamental Utilities for ECMAScript.

Downloads

2

Readme

es-first-aid

The Fundamental Utilities for ECMAScript.

  • Missing utility functions for ECMAScript
  • Random numbers/bytes...
  • UUIDs
  • CRC-32
  • Most basic general utility classes for various applications
  • Base64 encode/decode
  • UTF-8 string encode/decode
  • Hex string encode/decode
  • ...

API

globalThis.firstAid;

// where
declare const firstAid: FirstAid;

interface Iterable<T> {
    [Symbol.iterator](): Iterator<T>;
}

type BufferSource = ArrayBuffer | ArrayBufferView;

type MaybePromise<T> = Promise<T> | T;

interface PromiseComposition<T> extends Promise<Iterable<T>> {
    promises: Promise<T>[];
    [Symbol.iterator]: () => IterableIterator<T>;
    results: () => Promise<T[]>;
    rejections: () => Promise<any[]>;
    fulfilled: <returnType>(callback: (result: T) => returnType) => PromiseComposition<returnType>;
    rejected: <returnType>(callback: (reason: any) => returnType) => PromiseComposition<returnType>;
}

interface SymbolObject {
    symbol: symbol;
}

interface FirstAid {
    VERSION: string;

    firstAid: FirstAid;

    constructor: new () => FirstAid;

    PromiseComposition: new <T>(... promises: MaybePromise<T>[]) => PromiseComposition<T>;

    // TypedArray constructor. (This is abstract; you cannot instantiate this.)
    TypedArray: Function;

    // Returns true if the passed value is a TypedArray.
    isTypedArray: (value: any) => boolean;

    // -0.
    MINUS_ZERO: number;

    // Creates a new null-prototype object.
    createNullPrototypeObject: () => {};

    // Wraps an object in a read-only Proxy.
    createReadOnlyProxy: <T>(obj: T) => T;

    // Returns true if the function throws.
    checkForError: (f: () => void) => boolean;

    // Returns true if the passed object is a revoked Proxy.
    // This function is no longer always-reliable due to changes made to ECMAScript specs.
    isRevokedProxy: (value: any) => boolean;

    // Returns true if the passed object has a valid [[Construct]] slot.
    isConstructor: (value: any) => boolean;

    // Converts a value into a 32-bit signed integer.
    toInt32: (value: any) => number;

    // Returns true if the passed value is a 32-bit signed integer.
    isInt32: (value: any) => boolean;

    // Tries to convert a value into an integer.
    toInt: (value: any) => number;

    // Returns true if the passed value is a valid safe integer in ECMAScript.
    isInt: (value: any) => boolean;

    // Returns true if the passed value is null.
    isNull: (value: any) => boolean;

    // Returns true if the passed value is an object. (This includes functions but not null.)
    isObject: (value: any) => boolean;

    // Returns true if the passed value is a valid property key (string or symbol).
    isPropertyKey: (value: any) => boolean;

    // Returns Unicode code points of the given string.
    getCodePoints: (str: string) => Iterable<number>;

    // Encodes a string into UTF-8 bytes.
    encodeString: (str: string) => Uint8Array;

    // Decodes a string from UTF-8 bytes.
    decodeString: (utf8Bytes: BufferSource) => string;

    // Converts a buffer or view into a Uint8Array.
    toUint8Array: (buffer: BufferSource) => Uint8Array;

    // Get a copied ArrayBuffer from BufferSource.
    getCopyBuffer: (buffer: BufferSource) => ArrayBuffer;

    // Encodes bytes into a hex string.
    encodeHex: (buffer: BufferSource) => string;

    // Decodes a hex string.
    decodeHex: (hexString: string) => Uint8Array;

    // Encodes bytes into Base-64 encoded string.
    encodeBase64: (buffer: BufferSource) => string;

    // Decodes a Base-64 encoded string.
    decodeBase64: (base64String: string) => Uint8Array;

    // Calculates a CRC-32 check sum of the given buffer. (Signed 32-bit integer)
    crc32: (buffer: BufferSource) => number;

    // Get the CRC-32 sum as a Uint8Array.
    crc32Bytes: (buffer: BufferSource) => Uint8Array;

    // Fills the given buffer with Math.random() values.
    randomFillInsecure: (buffer: BufferSource) => Uint8Array;

    // Fills the given buffer with secure random values.
    // Currently, Node.JS, Web, and Deno is supported.
    randomFill: (buffer: BufferSource) => Uint8Array;

    // Returns a random number in [0, 1) range.
    // Uses Math.random() if isInsecure is true.
    random: (isInsecure?: boolean) => number;

    // Returns a random number in (0, 1] range.
    // Uses Math.random() if isInsecure is true.
    randomNonZero: (isInsecure?: boolean) => number;

    // Returns a standard normal random number.
    // Uses Math.random() if isInsecure is true.
    randomNormal: (isInsecure?: boolean) => number;

    // Returns a standard exponential random number.
    // Uses Math.random() if isInsecure is true.
    randomExponential: (isInsecure?: boolean) => number;

    // Returns a Xenakis random number.
    // Uses Math.random() if isInsecure is true.
    randomXenakis: (isInsecure?: boolean) => number;

    // Returns true in the given probability.
    // Uses Math.random() if isInsecure is true.
    randomProb: (prob: number, isInsecure?: boolean) => boolean;

    // Generates a version-4 UUID string from the given buffer.
    getUuidFromBytes: (arr: BufferSource) => string;

    // Generates a random version-4 UUID string.
    // Uses Math.random() if isInsecure is true.
    getRandomUuid: (isInsecure?: boolean) => string;

    // Returns true if the given value is a valid UUID string.
    validateUuid: (uuid: string) => boolean;

    // Calls the given function in an asynchronous manner.
    callAsync: <argumentType, returnType>(callback: (... argumentsList: argumentType[]) => MaybePromise<returnType>, thisArgument: any, ... argumentList: argumentType[]) => Promise<returnType>;

    // Converts any value into a Promise.
    toPromise: <T>(value: MaybePromise<T>) => Promise<T>;

    // Returns a current Unix timestamp in milliseconds.
    getTime: () => number;

    // Encodes an object into JSON bytes.
    encodeJson: (value: any) => Uint8Array;

    // Decodes an object from JSON bytes.
    decodeJson: (bytes: BufferSource) => any;

    // Throws an error if assertion is false
    assert: (assertion: boolean, message?: string) => void;

    // Returns the passed object as a constructor.
    IdentityConstructor: new <T>(obj: T) => T;

    // Creates an object for a symbol.
    SymbolObject: new (symbol: symbol | SymbolObject) => SymbolObject;
}

License

Copyright © 2021 Menhera.org

Licensed under the Apache 2.0 license.