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

@ndn/util

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndn/util - npm Package Compare versions

Comparing version 0.0.20230121 to 0.0.20240113

lib/event_browser.js

6

lib/closers_browser.js

@@ -15,2 +15,8 @@ /** A list of objects that can be closed or destroyed. */

}
/** Wait for close. */
wait() {
return new Promise((resolve) => {
this.push({ close: () => resolve() });
});
}
}

@@ -15,2 +15,8 @@ /** A list of objects that can be closed or destroyed. */

}
/** Wait for close. */
wait() {
return new Promise((resolve) => {
this.push({ close: () => resolve() });
});
}
}

2

lib/closers.d.ts

@@ -11,2 +11,4 @@ /// <reference types="node" />

addTimeout<T extends NodeJS.Timeout | number>(t: T): T;
/** Wait for close. */
wait(): Promise<void>;
}

@@ -0,1 +1,3 @@

import { __importDefault, __importStar } from "tslib";
import _cjsDefaultImport0 from "minimalistic-assert"; const assert = __importDefault(_cjsDefaultImport0).default;
/** Yield all values from an iterable but catch any error. */

@@ -19,1 +21,11 @@ export async function* safeIter(iterable, onError) {

}
/** Delete keys from a Set or Map until its size is below capacity. */
export function evict(capacity, ct) {
assert(capacity >= 0);
for (const key of ct.keys()) {
if (ct.size <= capacity) {
break;
}
ct.delete(key);
}
}

@@ -0,1 +1,3 @@

import { __importDefault, __importStar } from "tslib";
import _cjsDefaultImport0 from "minimalistic-assert"; const assert = __importDefault(_cjsDefaultImport0).default;
/** Yield all values from an iterable but catch any error. */

@@ -19,1 +21,11 @@ export async function* safeIter(iterable, onError) {

}
/** Delete keys from a Set or Map until its size is below capacity. */
export function evict(capacity, ct) {
assert(capacity >= 0);
for (const key of ct.keys()) {
if (ct.size <= capacity) {
break;
}
ct.delete(key);
}
}

10

lib/iter.d.ts

@@ -0,3 +1,4 @@

import type { AnyIterable } from "streaming-iterables";
/** Yield all values from an iterable but catch any error. */
export declare function safeIter<T>(iterable: AsyncIterable<T>, onError?: (err?: unknown) => void): AsyncIterableIterator<T>;
export declare function safeIter<T>(iterable: AnyIterable<T>, onError?: (err?: unknown) => void): AsyncIterableIterator<T>;
/**

@@ -7,2 +8,7 @@ * Map and flatten once.

*/
export declare function flatMapOnce<T, R>(f: (item: T) => Iterable<R> | AsyncIterable<R>, iterable: Iterable<T> | AsyncIterable<T>): AsyncIterable<R>;
export declare function flatMapOnce<T, R>(f: (item: T) => AnyIterable<R>, iterable: AnyIterable<T>): AsyncIterable<R>;
/** Delete keys from a Set or Map until its size is below capacity. */
export declare function evict<K>(capacity: number, ct: evict.Container<K>): void;
export declare namespace evict {
type Container<K> = Pick<Set<K> & Map<K, unknown>, "delete" | "size" | "keys">;
}
import { __importDefault, __importStar } from "tslib";
import _cjsDefaultImport0 from "minimalistic-assert"; const assert = __importDefault(_cjsDefaultImport0).default;
export { assert };
export { console, crypto, delay, concatBuffers } from "./platform_browser.js";
export { console, concatBuffers, crypto, delay } from "./platform_browser.js";
export * from "./buffer_browser.js";
export * from "./closers_browser.js";
export * from "./crypto_browser.js";
export * from "./event_browser.js";
export * from "./iter_browser.js";
export * from "./key-map_browser.js";
export * from "./number_browser.js";
export * from "./reorder_browser.js";
export * from "./string_browser.js";
export * from "./timer_browser.js";
import { __importDefault, __importStar } from "tslib";
import _cjsDefaultImport0 from "minimalistic-assert"; const assert = __importDefault(_cjsDefaultImport0).default;
export { assert };
export { console, crypto, delay, concatBuffers } from "./platform_node.js";
export { console, concatBuffers, crypto, delay } from "./platform_node.js";
export * from "./buffer_node.js";
export * from "./closers_node.js";
export * from "./crypto_node.js";
export * from "./event_node.js";
export * from "./iter_node.js";
export * from "./key-map_node.js";
export * from "./number_node.js";
export * from "./reorder_node.js";
export * from "./string_node.js";
export * from "./timer_node.js";
import assert from "minimalistic-assert";
export { assert };
export { console, crypto, delay, concatBuffers } from "./platform_node.js";
export { console, concatBuffers, crypto, delay } from "./platform_node.js";
export * from "./buffer.js";
export * from "./closers.js";
export * from "./crypto.js";
export * from "./event.js";
export * from "./iter.js";
export * from "./key-map.js";
export * from "./number.js";
export * from "./reorder.js";
export * from "./string.js";
export * from "./timer.js";

@@ -0,5 +1,9 @@

export declare function concatBuffers(list: readonly Uint8Array[], totalLength?: number): Uint8Array;
export declare const console: Console;
export declare const crypto: Crypto;
export declare const CustomEvent: {
new <T>(type: string, eventInitDict?: CustomEventInit<T> | undefined): CustomEvent<T>;
prototype: CustomEvent<any>;
};
export declare function delay<T = void>(after: number, value?: T): Promise<T>;
export declare function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
export declare function delay<T = void>(after: number, value?: T): Promise<T>;
export declare function concatBuffers(list: readonly Uint8Array[], totalLength?: number): Uint8Array;
import { __importDefault, __importStar } from "tslib";
import _cjsDefaultImport0 from "minimalistic-assert"; const assert = __importDefault(_cjsDefaultImport0).default;
export const console = globalThis.console;
export const crypto = globalThis.crypto;
// https://codahale.com/a-lesson-in-timing-attacks/
export function timingSafeEqual(a, b) {
// length has been checked by caller
let result = 0;
for (let i = 0; i < a.byteLength; ++i) {
result |= a[i] ^ b[i];
}
return result === 0;
}
export function delay(after, value) {
return new Promise((resolve) => setTimeout(resolve, after, value));
}
export function concatBuffers(list, totalLength) {

@@ -28,1 +14,26 @@ totalLength ??= list.reduce((l, { byteLength }) => l + byteLength, 0);

}
export const console = globalThis.console;
export const crypto = globalThis.crypto;
if (!crypto.subtle && !globalThis.isSecureContext) {
Object.defineProperty(crypto, "subtle", {
configurable: true,
get() {
console.error("NDNts depends on Web Crypto but it is unavailable because this webpage is not delivered securely, " +
"see https://mdn.io/SecureContext");
return undefined;
},
});
}
export const CustomEvent = globalThis.CustomEvent;
export function delay(after, value) {
return new Promise((resolve) => setTimeout(resolve, after, value));
}
export function timingSafeEqual(a, b) {
// length has been checked by caller
// https://codahale.com/a-lesson-in-timing-attacks/
let result = 0;
for (let i = 0; i < a.byteLength; ++i) {
result |= a[i] ^ b[i];
}
return result === 0;
}

@@ -0,3 +1,6 @@

/// <reference types="node" />
import { timingSafeEqual } from "node:crypto";
export { timingSafeEqual };
/** Concatenate Uint8Arrays. */
export declare function concatBuffers(arr: readonly Uint8Array[], totalLength?: number): Uint8Array;
/** Console on stderr. */

@@ -7,5 +10,5 @@ export declare const console: Console;

export declare const crypto: Crypto;
/** CustomEvent object. */
export declare const CustomEvent: typeof globalThis["CustomEvent"];
/** Make a Promise that resolves after specified duration. */
export declare const delay: <T = void>(after: number, value?: T) => Promise<T>;
/** Concatenate Uint8Arrays. */
export declare function concatBuffers(arr: readonly Uint8Array[], totalLength?: number): Uint8Array;

@@ -5,2 +5,6 @@ import { Console } from "node:console";

export { timingSafeEqual };
/** Concatenate Uint8Arrays. */
export function concatBuffers(arr, totalLength) {
return Buffer.concat(arr, totalLength);
}
/** Console on stderr. */

@@ -10,7 +14,12 @@ export const console = new Console(process.stderr);

export const crypto = webcrypto;
class CustomEventPonyfill extends Event {
constructor(type, options) {
super(type, options);
this.detail = options?.detail;
}
detail;
}
/** CustomEvent object. */
export const CustomEvent = globalThis.CustomEvent ?? CustomEventPonyfill;
/** Make a Promise that resolves after specified duration. */
export const delay = setTimeoutPromise;
/** Concatenate Uint8Arrays. */
export function concatBuffers(arr, totalLength) {
return Buffer.concat(arr, totalLength);
}

@@ -15,10 +15,1 @@ /**

}
function timeoutAbortSignalFallback(time) {
// Node.js 16.x lacks global DOMException, but it has AbortSignal.timeout so this fallback won't
// be called. As of 20220601, this fallback is needed for Chrome, etc.
const abort = new AbortController();
setTimeout(() => abort.abort(new DOMException("TimeoutError", "TimeoutError")), time);
return abort.signal;
}
/** AbortSignal.timeout ponyfill. */
export const timeoutAbortSignal = AbortSignal.timeout ?? timeoutAbortSignalFallback;

@@ -15,10 +15,1 @@ /**

}
function timeoutAbortSignalFallback(time) {
// Node.js 16.x lacks global DOMException, but it has AbortSignal.timeout so this fallback won't
// be called. As of 20220601, this fallback is needed for Chrome, etc.
const abort = new AbortController();
setTimeout(() => abort.abort(new DOMException("TimeoutError", "TimeoutError")), time);
return abort.signal;
}
/** AbortSignal.timeout ponyfill. */
export const timeoutAbortSignal = AbortSignal.timeout ?? timeoutAbortSignalFallback;

@@ -10,3 +10,1 @@ /**

export declare function randomJitter(r: number, x?: number): () => number;
/** AbortSignal.timeout ponyfill. */
export declare const timeoutAbortSignal: (time: number) => AbortSignal;
{
"name": "@ndn/util",
"version": "0.0.20230121",
"version": "0.0.20240113",
"description": "NDNts: general utilities",

@@ -25,10 +25,11 @@ "keywords": [

"dependencies": {
"@types/minimalistic-assert": "^1.0.1",
"@types/minimalistic-assert": "^1.0.3",
"minimalistic-assert": "^1.0.1",
"tslib": "^2.4.1"
"streaming-iterables": "^8.0.1",
"tslib": "^2.6.2"
},
"engines": {
"node": "^16.17.1 || ^18.10.0 || ^19.0.0"
"node": "^18.18.0 || ^20.0.0 || ^21.0.0"
},
"types": "lib/mod.d.ts"
}
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