Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jmisc

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jmisc - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

2

cjs/index.d.ts

@@ -8,4 +8,4 @@ export { isBrowser, ensureBrowser } from './dom.js';

export { capitalize, uncapitalize, base64ToURI, uriToBase64, isoBtoa, isoAtob, normalizeVietnamese } from './str.js';
export { sleep, cancellableSleep, setTimeoutUntil, setTimeoutUnlimited, timeoutWait } from './time.js';
export { sleep, setTimeoutUntil } from './time.js';
export { as } from './type.js';
export type { IgnoreLastIfVoid, UndefinedToNull, Nullable, UnionToIntersection, AllOrNone, Promisable } from './type.js';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.as = exports.timeoutWait = exports.setTimeoutUnlimited = exports.setTimeoutUntil = exports.cancellableSleep = exports.sleep = exports.normalizeVietnamese = exports.isoAtob = exports.isoBtoa = exports.uriToBase64 = exports.base64ToURI = exports.uncapitalize = exports.capitalize = exports.zip = exports.isObject = exports.emptyArray = exports.emptyObject = exports.objectMap = exports.pluck = exports.omit = exports.pick = exports.deepPick = exports.set = exports.get = exports.deepHas = exports.recursiveSet = exports.floatToStr = exports.isInteger = exports.isValidNumber = exports.makeLazySync = exports.makeMemoize = exports.makeLazy = exports.concatBuffers = exports.readableStreamToAsyncIterator = exports.asyncIteratorToArray = exports.not = exports.noop = exports.identity = exports.negate = exports.ensureBrowser = exports.isBrowser = void 0;
exports.as = exports.setTimeoutUntil = exports.sleep = exports.normalizeVietnamese = exports.isoAtob = exports.isoBtoa = exports.uriToBase64 = exports.base64ToURI = exports.uncapitalize = exports.capitalize = exports.zip = exports.isObject = exports.emptyArray = exports.emptyObject = exports.objectMap = exports.pluck = exports.omit = exports.pick = exports.deepPick = exports.set = exports.get = exports.deepHas = exports.recursiveSet = exports.floatToStr = exports.isInteger = exports.isValidNumber = exports.makeLazySync = exports.makeMemoize = exports.makeLazy = exports.concatBuffers = exports.readableStreamToAsyncIterator = exports.asyncIteratorToArray = exports.not = exports.noop = exports.identity = exports.negate = exports.ensureBrowser = exports.isBrowser = void 0;
var dom_js_1 = require("./dom.js");

@@ -48,8 +48,5 @@ Object.defineProperty(exports, "isBrowser", { enumerable: true, get: function () { return dom_js_1.isBrowser; } });

Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return time_js_1.sleep; } });
Object.defineProperty(exports, "cancellableSleep", { enumerable: true, get: function () { return time_js_1.cancellableSleep; } });
Object.defineProperty(exports, "setTimeoutUntil", { enumerable: true, get: function () { return time_js_1.setTimeoutUntil; } });
Object.defineProperty(exports, "setTimeoutUnlimited", { enumerable: true, get: function () { return time_js_1.setTimeoutUnlimited; } });
Object.defineProperty(exports, "timeoutWait", { enumerable: true, get: function () { return time_js_1.timeoutWait; } });
var type_js_1 = require("./type.js");
Object.defineProperty(exports, "as", { enumerable: true, get: function () { return type_js_1.as; } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsbUNBQWlEO0FBQXpDLG1HQUFBLFNBQVMsT0FBQTtBQUFFLHVHQUFBLGFBQWEsT0FBQTtBQUNoQyxxQ0FBcUQ7QUFBN0MsaUdBQUEsTUFBTSxPQUFBO0FBQUUsbUdBQUEsUUFBUSxPQUFBO0FBQUUsK0ZBQUEsSUFBSSxPQUFBO0FBQUUsOEZBQUEsR0FBRyxPQUFBO0FBQ25DLG1EQUFtRztBQUEzRixzSEFBQSxvQkFBb0IsT0FBQTtBQUFFLCtIQUFBLDZCQUE2QixPQUFBO0FBQUUsK0dBQUEsYUFBYSxPQUFBO0FBQzFFLHFDQUE2RDtBQUFyRCxtR0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ZILG1DQUFrSDtBQUExRyxvR0FBQSxVQUFVLE9BQUE7QUFBRSxzR0FBQSxZQUFZLE9BQUE7QUFBRSxxR0FBQSxXQUFXLE9BQUE7QUFBRSxxR0FBQSxXQUFXLE9BQUE7QUFBRSxpR0FBQSxPQUFPLE9BQUE7QUFBRSxpR0FBQSxPQUFPLE9BQUE7QUFBRSw2R0FBQSxtQkFBbUIsT0FBQTtBQUNqRyxxQ0FBZ0Q7QUFBeEMsZ0dBQUEsS0FBSyxPQUFBO0FBQUUsMEdBQUEsZUFBZSxPQUFBO0FBQzlCLHFDQUE0QjtBQUFwQiw2RkFBQSxFQUFFLE9BQUEifQ==

@@ -1,11 +0,2 @@

/// <reference types="node" />
import type { MutableRefObject } from 'react';
export declare function sleep(millisecond: number): Promise<unknown>;
export declare function cancellableSleep(millisecond: number): {
promise: Promise<void>;
cancel(): void;
};
export declare function setTimeoutUntil(cb: () => any, end: number): MutableRefObject<ReturnType<typeof setTimeout>>;
export declare function setTimeoutUnlimited(cb: () => any, timeout: number): MutableRefObject<NodeJS.Timeout>;
export declare function timeoutWait<T, V>(promise: Promise<T>, time: number, fallback: V): Promise<T | V>;
export declare function timeoutWait<T>(promise: Promise<T>, time: number): Promise<T | undefined>;
export declare function setTimeoutUntil(cb: () => any, until: number): () => void;
"use strict";
// eslint-disable-next-line no-promise-executor-return
Object.defineProperty(exports, "__esModule", { value: true });
exports.timeoutWait = exports.setTimeoutUnlimited = exports.setTimeoutUntil = exports.cancellableSleep = exports.sleep = void 0;
exports.setTimeoutUntil = exports.sleep = void 0;
// hint: in node enviroent, use 'timers/promises/setTimeout'
function sleep(millisecond) {

@@ -8,20 +10,2 @@ return new Promise(resolve => void setTimeout(resolve, millisecond));

exports.sleep = sleep;
function cancellableSleep(millisecond) {
let timeout;
// eslint-disable-next-line no-promise-executor-return
const promise = new Promise(resolve => void (timeout = setTimeout(() => {
timeout = undefined;
resolve();
}, millisecond)));
return {
promise,
cancel() {
if (timeout) {
clearTimeout(timeout);
timeout = undefined;
}
},
};
}
exports.cancellableSleep = cancellableSleep;
// https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value

@@ -33,36 +17,24 @@ const MAX_TIMEOUT = 2_147_483_647;

// Passing an invalid ID to clearTimeout() silently does nothing; no exception is thrown.
const setTimeoutUntilRef = (cb, end, ref) => {
const diff = end - Date.now();
ref.current = diff <= MAX_TIMEOUT
? setTimeout(cb, Math.max(diff, 0))
: setTimeout(() => {
setTimeoutUntilRef(cb, end, ref);
}, MAX_TIMEOUT);
};
// timeout has limit of 2147483647
function setTimeoutUntil(cb, end) {
const ref = { current: undefined };
setTimeoutUntilRef(cb, end, ref);
return ref;
function setTimeoutUntil(cb, until) {
let timeout;
const sub = (cb, until) => {
const diff = until - Date.now();
if (diff <= MAX_TIMEOUT) {
timeout = setTimeout(cb, Math.max(diff, 0));
}
else {
timeout = setTimeout(() => {
sub(cb, until);
}, MAX_TIMEOUT);
}
};
sub(cb, until);
return () => {
if (timeout)
clearTimeout(timeout);
timeout = undefined;
};
}
exports.setTimeoutUntil = setTimeoutUntil;
function setTimeoutUnlimited(cb, timeout) {
return setTimeoutUntil(cb, Date.now() + timeout);
}
exports.setTimeoutUnlimited = setTimeoutUnlimited;
async function timeoutWait(promise, time, fallback = undefined) {
if (time <= 0)
return fallback;
const { promise: timeoutPromise, cancel } = cancellableSleep(time);
try {
return await Promise.race([
promise,
timeoutPromise.then(() => fallback),
]);
}
finally {
cancel();
}
}
exports.timeoutWait = timeoutWait;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGltZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90aW1lLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUlBLFNBQWdCLEtBQUssQ0FBQyxXQUFtQjtJQUN4QyxPQUFPLElBQUksT0FBTyxDQUFDLE9BQU8sQ0FBQyxFQUFFLENBQUMsS0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sSUFBSSxFQUFFLENBQUMsQ0FBQyxDQUFDLENBQUE7U0FDM0M7YUFBTTtZQUNOLE9BQU8sR0FBRyxVQUFVLENBQUMsR0FBRyxFQUFFO2dCQUN6QixHQUFHLENBQUMsRUFBRSxFQUFFLEtBQUssQ0FBQyxDQUFBO1lBQ2YsQ0FBQyxFQUFFLFdBQVcsQ0FBQyxDQUFBO1NBQ2Y7SUFDRixDQUFDLENBQUE7SUFDRCxHQUFHLENBQUMsRUFBRSxFQUFFLEtBQUssQ0FBQyxDQUFBO0lBQ2QsT0FBTyxHQUFHLEVBQUU7UUFDWCxJQUFJLE9BQU87WUFBRSxZQUFZLENBQUMsT0FBTyxDQUFDLENBQUE7UUFDbEMsT0FBTyxHQUFHLFNBQVMsQ0FBQTtJQUNwQixDQUFDLENBQUE7QUFDRixDQUFDO0FBeEJELDBDQXdCQyJ9

@@ -8,4 +8,4 @@ export { isBrowser, ensureBrowser } from './dom.js';

export { capitalize, uncapitalize, base64ToURI, uriToBase64, isoBtoa, isoAtob, normalizeVietnamese } from './str.js';
export { sleep, cancellableSleep, setTimeoutUntil, setTimeoutUnlimited, timeoutWait } from './time.js';
export { sleep, setTimeoutUntil } from './time.js';
export { as } from './type.js';
export type { IgnoreLastIfVoid, UndefinedToNull, Nullable, UnionToIntersection, AllOrNone, Promisable } from './type.js';

@@ -8,4 +8,4 @@ export { isBrowser, ensureBrowser } from './dom.js';

export { capitalize, uncapitalize, base64ToURI, uriToBase64, isoBtoa, isoAtob, normalizeVietnamese } from './str.js';
export { sleep, cancellableSleep, setTimeoutUntil, setTimeoutUnlimited, timeoutWait } from './time.js';
export { sleep, setTimeoutUntil } from './time.js';
export { as } from './type.js';
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0F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mMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFDLFNBQVMsRUFBRSxhQUFhLEVBQUMsTUFBTSxVQUFVLENBQUE7QUFDakQsT0FBTyxFQUFDLE1BQU0sRUFBRSxRQUFRLEVBQUUsSUFBSSxFQUFFLEdBQUcsRUFBQyxNQUFNLFdBQVcsQ0FBQTtBQUNyRCxPQUFPLEVBQUMsb0JBQW9CLEVBQUUsNkJBQTZCLEVBQUUsYUFBYSxFQUFDLE1BQU0sa0JBQWtCLENBQUE7QUFDbkcsT0FBTyxFQUFDLFFBQVEsRUFBRSxXQUFXLEVBQUUsWUFBWSxFQUFDLE1BQU0sV0FBVyxDQUFBO0FBQzdELE9BQU8sRUFBQyxhQUFhLEVBQUUsU0FBUyxFQUFFLFVBQVUsRUFBQyxNQUFNLFVBQVUsQ0FBQTtBQUM3RCxPQUFPLEVBQUMsWUFBWSxFQUFFLE9BQU8sRUFBRSxHQUFHLEVBQUUsR0FBRyxFQUFFLFFBQVEsRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLEtBQUssRUFBRSxTQUFTLEVBQUUsV0FBVyxFQUFFLFVBQVUsRUFBRSxRQUFRLEVBQUUsR0FBRyxFQUFDLE1BQU0sVUFBVSxDQUFBO0FBQ3hJLE9BQU8sRUFBQyxVQUFVLEVBQUUsWUFBWSxFQUFFLFdBQVcsRUFBRSxXQUFXLEVBQUUsT0FBTyxFQUFFLE9BQU8sRUFBRSxtQkFBbUIsRUFBQyxNQUFNLFVBQVUsQ0FBQTtBQUNsSCxPQUFPLEVBQUMsS0FBSyxFQUFFLGVBQWUsRUFBQyxNQUFNLFdBQVcsQ0FBQTtBQUNoRCxPQUFPLEVBQUMsRUFBRSxFQUFDLE1BQU0sV0FBVyxDQUFBIn0=

@@ -1,11 +0,2 @@

/// <reference types="node" />
import type { MutableRefObject } from 'react';
export declare function sleep(millisecond: number): Promise<unknown>;
export declare function cancellableSleep(millisecond: number): {
promise: Promise<void>;
cancel(): void;
};
export declare function setTimeoutUntil(cb: () => any, end: number): MutableRefObject<ReturnType<typeof setTimeout>>;
export declare function setTimeoutUnlimited(cb: () => any, timeout: number): MutableRefObject<NodeJS.Timeout>;
export declare function timeoutWait<T, V>(promise: Promise<T>, time: number, fallback: V): Promise<T | V>;
export declare function timeoutWait<T>(promise: Promise<T>, time: number): Promise<T | undefined>;
export declare function setTimeoutUntil(cb: () => any, until: number): () => void;

@@ -0,21 +1,6 @@

// eslint-disable-next-line no-promise-executor-return
// hint: in node enviroent, use 'timers/promises/setTimeout'
export function sleep(millisecond) {
return new Promise(resolve => void setTimeout(resolve, millisecond));
}
export function cancellableSleep(millisecond) {
let timeout;
// eslint-disable-next-line no-promise-executor-return
const promise = new Promise(resolve => void (timeout = setTimeout(() => {
timeout = undefined;
resolve();
}, millisecond)));
return {
promise,
cancel() {
if (timeout) {
clearTimeout(timeout);
timeout = undefined;
}
},
};
}
// https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value

@@ -27,33 +12,23 @@ const MAX_TIMEOUT = 2_147_483_647;

// Passing an invalid ID to clearTimeout() silently does nothing; no exception is thrown.
const setTimeoutUntilRef = (cb, end, ref) => {
const diff = end - Date.now();
ref.current = diff <= MAX_TIMEOUT
? setTimeout(cb, Math.max(diff, 0))
: setTimeout(() => {
setTimeoutUntilRef(cb, end, ref);
}, MAX_TIMEOUT);
};
// timeout has limit of 2147483647
export function setTimeoutUntil(cb, end) {
const ref = { current: undefined };
setTimeoutUntilRef(cb, end, ref);
return ref;
export function setTimeoutUntil(cb, until) {
let timeout;
const sub = (cb, until) => {
const diff = until - Date.now();
if (diff <= MAX_TIMEOUT) {
timeout = setTimeout(cb, Math.max(diff, 0));
}
else {
timeout = setTimeout(() => {
sub(cb, until);
}, MAX_TIMEOUT);
}
};
sub(cb, until);
return () => {
if (timeout)
clearTimeout(timeout);
timeout = undefined;
};
}
export function setTimeoutUnlimited(cb, timeout) {
return setTimeoutUntil(cb, Date.now() + timeout);
}
export async function timeoutWait(promise, time, fallback = undefined) {
if (time <= 0)
return fallback;
const { promise: timeoutPromise, cancel } = cancellableSleep(time);
try {
return await Promise.race([
promise,
timeoutPromise.then(() => fallback),
]);
}
finally {
cancel();
}
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGltZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90aW1lLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUlBLE1BQU0sVUFBVSxLQUFLLENBQUMsV0FBbUI7SUFDeEMsT0FBTyxJQUFJLE9BQU8sQ0FBQyxPQUFPLENBQUMsRUFBRSxDQUFDLEtBQUssVUFBVSxDQUFDLE9BQU8sRUFBRSxXQUFXLENBQUMsQ0FBQyxDQUFBO0FBQ3JFLENBQUM7QUFFRCxNQUFNLFVBQVUsZ0JBQWdCLENBQUMsV0FBbUI7SUFDbkQsSUFBSSxPQUFrRCxDQUFBO0lBQ3RELHNEQUFzRDtJQUN0RCxNQUFNLE9BQU8sR0FBRyxJQUFJLE9BQU8sQ0FBTyxPQUFPLENBQUMsRUFBRSxDQUFDLEtBQUssQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDLEdBQUcsRUFBRTtRQUM1RSxPQUFPLEdBQUcsU0FBUyxDQUFBO1FBQ25CLE9BQU8sRUFBRSxDQUFBO0lBQ1YsQ0FBQyxFQUFFLFdBQVcsQ0FBQyxDQUFDLENBQUMsQ0FBQTtJQUNqQixPQUFPO1FBQ04sT0FBTztRQUNQLE1BQU07WUFDTCxJQUFJLE9BQU8sRUFBRTtnQkFDWixZQUFZLENBQUMsT0FBTyxDQUFDLENBQUE7Z0JBQ3JCLE9BQU8sR0FBRyxTQUFTLENBQUE7YUFDbkI7UUFDRixDQUFDO0tBQ0QsQ0FBQTtBQUNGLENBQUM7QUFFRCxrRkFBa0Y7QUFDbEYsTUFBTSxXQUF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QUFhLEVBQ2IsS0FBYTtJQUViLElBQUksT0FBa0QsQ0FBQTtJQUV0RCxNQUFNLEdBQUcsR0FBRyxDQUNYLEVBQWEsRUFDYixLQUFhLEVBQ1osRUFBRTtRQUNILE1BQU0sSUFBSSxHQUFHLEtBQUssR0FBRyxJQUFJLENBQUMsR0FBRyxFQUFFLENBQUE7UUFDL0IsSUFBSSxJQUFJLElBQUksV0FBVyxFQUFFO1lBQ3hCLE9BQU8sR0FBRyxVQUFVLENBQUMsRUFBRSxFQUFFLElBQUksQ0FBQyxHQUFHLENBQUMsSUFBSSxFQUFFLENBQUMsQ0FBQyxDQUFDLENBQUE7U0FDM0M7YUFBTTtZQUNOLE9BQU8sR0FBRyxVQUFVLENBQUMsR0FBRyxFQUFFO2dCQUN6QixHQUFHLENBQUMsRUFBRSxFQUFFLEtBQUssQ0FBQyxDQUFBO1lBQ2YsQ0FBQyxFQUFFLFdBQVcsQ0FBQyxDQUFBO1NBQ2Y7SUFDRixDQUFDLENBQUE7SUFDRCxHQUFHLENBQUMsRUFBRSxFQUFFLEtBQUssQ0FBQyxDQUFBO0lBQ2QsT0FBTyxHQUFHLEVBQUU7UUFDWCxJQUFJLE9BQU87WUFBRSxZQUFZLENBQUMsT0FBTyxDQUFDLENBQUE7UUFDbEMsT0FBTyxHQUFHLFNBQVMsQ0FBQTtJQUNwQixDQUFDLENBQUE7QUFDRixDQUFDIn0=
{
"name": "jmisc",
"version": "0.0.9",
"version": "0.0.10",
"main": "cjs/index.js",

@@ -5,0 +5,0 @@ "exports": {

@@ -13,5 +13,5 @@ # jmisc - Javascript utilities tool

export {capitalize, uncapitalize, base64ToURI, uriToBase64, isoBtoa, isoAtob, normalizeVietnamese} from './str'
export {sleep, cancellableSleep, setTimeoutUntil, setTimeoutUnlimited, timeoutWait} from './time'
export {sleep, setTimeoutUntil} from './time'
export {as} from './type'
export type {IgnoreLastIfVoid, UndefinedToNull, Nullable, UnionToIntersection, AllOrNone, Promisable} from './type'
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc