Skip to content

GrosSacASac/utilsac

Repository files navigation

Utility functions

Installation

npm i utilsac

Usage

The source code is the documentation.

utility.js

import {
    createDebounced,
    createThrottled,
    throttledWithLast,
    chainPromiseNTimes,
    chainPromises,
    forceThrottlePromiseCreator,
    throttlePromiseCreator,
    throttlePromiseCreatorSelfClean,
    somePromisesParallel,
    chainRequestAnimationFrame,
    decorateForceSequential,
    doNTimes,
    timeFunction,
    timePromise,
    memoizeAsStrings,
    createTemplateTag,
    bytesLengthFromString,
    assignSelected,
} from "utilsac";

// deno
import {
    createDebounced,
    createThrottled,
    throttledWithLast,
    chainPromises,
    somePromisesParallel,
    chainRequestAnimationFrame,
    doNTimes,
    chainPromiseNTimes,
    timeFunction,
    timePromise,
    memoizeAsStrings,
    createTemplateTag,
    bytesLengthFromString,
} from "https://unpkg.com/utilsac/utility.js";

deep.js

Consider structuredClone if you need deepCopy

import {
    deepCopy,
    deepCopyAdded,
    deepAssign,
    deepAssignAdded,
    deepEqual,
    deepEqualAdded,
    deepDifference,
} from "utilsac/deep.js";

// deno
import {
    deepCopy,
    deepCopyAdded,
    deepAssign,
    deepAssignAdded,
    deepEqual,
    deepEqualAdded,
    deepDifference,
} from "https://unpkg.com/utilsac/deep.js";

deepEqual example

const personA = { email: 'example@email.com', name: { firstname: 'James', lastname: 'William' }};

const personB = { email: 'example@email.com', name: { firstname: 'James', lastname: 'William' }};

deepEqual(personA, personB); //  true

typeCast.js

import {
    stringFromArrayBuffer,
    arrayBufferFromBlob,
    stringFromBlob,
    stringFromArray,
    setFromArray,
    mapFromObject,
} from "utilsac/typeCast.js";

// deno
import {
    deepCopy,
    deepCopyAdded,
    deepAssign,
    deepAssignAdded,
    deepEqual,
    deepEqualAdded,
    deepDifference,
} from "https://unpkg.com/utilsac/typeCast.js";

browserUtility.js

import { 
    evalGlobal,
    downloadBlob,
} from "utilsac/browserUtility.js";
evalGlobal(`window.x = 2 ** 10`);

After the Promise is resolved the code has executed in global scope.

evalGlobal(`
import sin form "./x.js";
window.x = sin(Math.PI)
`, `module`);

Use optional second argument with module to be able to use static imports

About

Changelog

Changelog

License

CC0

Related