@dhmk/utils
Advanced tools
Comparing version 0.0.3 to 1.0.0
@@ -1,26 +0,11 @@ | ||
export declare const noop: () => void; | ||
export declare type Signal<T> = T extends void ? { | ||
emit(): void; | ||
observe(onValue: () => void, onDispose?: () => void): () => void; | ||
} : { | ||
emit(value: T): void; | ||
observe(onValue: (value: T) => void, onDispose?: () => void): () => void; | ||
}; | ||
export declare const signal: <T = void>() => Signal<T>; | ||
export declare class AggregateError extends Error { | ||
readonly errors: ReadonlyArray<Error>; | ||
constructor(errors: ReadonlyArray<Error>); | ||
} | ||
export declare const disposable: (...fns: Function[]) => () => void; | ||
export declare const sleep: (ms: number) => Promise<unknown>; | ||
export declare type Deferred<T> = Promise<T> & { | ||
reject(error: Error): Deferred<T>; | ||
} & (T extends void ? { | ||
resolve(): Deferred<T>; | ||
} : { | ||
resolve(x: T): Deferred<T>; | ||
}); | ||
export declare const deferred: <T = void>() => Deferred<T>; | ||
export declare type Action = (...args: any[]) => void; | ||
export declare const debounced: <T extends Action>(fn: T, ms: number) => (...args: Parameters<T>) => void; | ||
export declare const throttled: <T extends Action>(fn: T, ms: number) => (...args: Parameters<T>) => void; | ||
export * from "./cancellable"; | ||
export * from "./error"; | ||
export * from "./fn"; | ||
export * from "./imm"; | ||
export * from "./misc"; | ||
export * from "./proxy"; | ||
export * from "./queue"; | ||
export * from "./signal"; | ||
export * from "./std"; | ||
export * from "./types"; | ||
export * from "./entries"; |
100
lib/index.js
@@ -1,79 +0,23 @@ | ||
export const noop = () => { }; | ||
class _Signal { | ||
constructor() { | ||
this.fns = new Set(); | ||
} | ||
emit(value) { | ||
for (const fn of this.fns) | ||
fn(value); | ||
} | ||
observe(onValue, onDispose = noop) { | ||
this.fns.add(onValue); | ||
return () => { | ||
this.fns.delete(onValue) && onDispose(); | ||
}; | ||
} | ||
} | ||
export const signal = () => new _Signal(); | ||
export class AggregateError extends Error { | ||
constructor(errors) { | ||
super(`One or more errors have occurred: ${errors}`); | ||
this.errors = errors; | ||
this.name = "AggregateError"; | ||
} | ||
} | ||
export const disposable = (...fns) => { | ||
let isDisposed = false; | ||
return () => { | ||
if (isDisposed) | ||
return; | ||
isDisposed = true; | ||
const errors = []; | ||
for (const fn of fns) { | ||
try { | ||
fn(); | ||
} | ||
catch (e) { | ||
errors.push(e); | ||
} | ||
} | ||
if (errors.length) { | ||
throw new AggregateError(errors); | ||
} | ||
}; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
export const sleep = (ms) => new Promise((res) => setTimeout(res, ms)); | ||
export const deferred = () => { | ||
const self = {}; | ||
const p = new Promise((res, rej) => { | ||
self.resolve = (x) => { | ||
res(x); | ||
return self; | ||
}; | ||
self.reject = (e) => { | ||
rej(e); | ||
return self; | ||
}; | ||
}); | ||
self.then = p.then.bind(p); | ||
self.catch = p.catch.bind(p); | ||
self.finally = p.finally.bind(p); | ||
return self; | ||
}; | ||
export const debounced = (fn, ms) => { | ||
let tid; | ||
return (...args) => { | ||
clearTimeout(tid); | ||
tid = setTimeout(() => fn(...args), ms); | ||
}; | ||
}; | ||
export const throttled = (fn, ms) => { | ||
let muted = false; | ||
return (...args) => { | ||
if (muted) | ||
return; | ||
fn(...args); | ||
muted = true; | ||
setTimeout(() => (muted = false), ms); | ||
}; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./cancellable"), exports); | ||
__exportStar(require("./error"), exports); | ||
__exportStar(require("./fn"), exports); | ||
__exportStar(require("./imm"), exports); | ||
__exportStar(require("./misc"), exports); | ||
__exportStar(require("./proxy"), exports); | ||
__exportStar(require("./queue"), exports); | ||
__exportStar(require("./signal"), exports); | ||
__exportStar(require("./std"), exports); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./entries"), exports); |
{ | ||
"name": "@dhmk/utils", | ||
"version": "0.0.3", | ||
"description": "A collection of frequently used functions", | ||
"version": "1.0.0", | ||
"description": "A collection of frequently used functions and primitives", | ||
"keywords": [ | ||
"utils", | ||
"tools", | ||
"functions" | ||
"functions", | ||
"helpers", | ||
"misc" | ||
], | ||
"homepage": "https://github.com/dhmk083/dhmk-utils", | ||
"bugs": "https://github.com/dhmk083/dhmk-utils/issues", | ||
"license": "MIT", | ||
"repository": "github:dhmk083/dhmk-utils", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"license": "MIT", | ||
"module": "esm/index.js", | ||
"sideEffects": false, | ||
"files": [ | ||
"lib" | ||
"lib", | ||
"esm" | ||
], | ||
"sideEffects": false, | ||
"_esnext": true, | ||
"scripts": { | ||
@@ -24,4 +26,4 @@ "preversion": "yarn test && yarn build", | ||
"postversion": "git push && git push --tags", | ||
"clean": "rm -rf lib", | ||
"build": "yarn clean && tsc", | ||
"clean": "rm -rf lib esm", | ||
"build": "yarn clean && tsc && tsc -m esnext --outDir esm", | ||
"test": "yarn clean && jest" | ||
@@ -33,4 +35,7 @@ }, | ||
"ts-jest": "^26.4.4", | ||
"typescript": "^4.1.3" | ||
"typescript": "^4.2.3" | ||
}, | ||
"jest": { | ||
"preset": "ts-jest" | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
# A collection of frequently used functions. | ||
# A collection of frequently used functions and primitives. | ||
For more info see [src/index.ts](src/index.ts) or [lib/index.d.ts](lib/index.d.ts). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
81578
62
1947
1