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

@dhmk/utils

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dhmk/utils - npm Package Compare versions

Comparing version 0.0.3 to 1.0.0

esm/cancellable.d.ts

37

lib/index.d.ts

@@ -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";

@@ -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).
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