Socket
Socket
Sign inDemoInstall

@syncot/util

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@syncot/util - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

4

lib/event.d.ts

@@ -54,3 +54,5 @@ /// <reference types="node" />

*/
export declare const TypedEventEmitter: new <ListenEvents, EmitEvents = ListenEvents>() => TypedEventEmitterInterface<ListenEvents, EmitEvents>;
declare const _TypedEventEmitter: new <ListenEvents, EmitEvents = ListenEvents>() => TypedEventEmitterInterface<ListenEvents, EmitEvents>;
export declare class TypedEventEmitter<ListenEvents, EmitEvents = ListenEvents> extends _TypedEventEmitter<ListenEvents, EmitEvents> {
}
/**

@@ -57,0 +59,0 @@ * A strongly-typed event emitter based on nodejs `EventEmitter`.

@@ -21,4 +21,5 @@ import { EventEmitter } from 'events';

*/
// tslint:disable-next-line:variable-name
export const TypedEventEmitter = EventEmitter;
const _TypedEventEmitter = EventEmitter;
export class TypedEventEmitter extends _TypedEventEmitter {
}
/**

@@ -25,0 +26,0 @@ * A strongly-typed event emitter based on nodejs `EventEmitter`.

@@ -7,2 +7,1 @@ export * from './buffer';

export * from './taskRunner';
export * from './validation';

@@ -7,2 +7,1 @@ export * from './buffer';

export * from './taskRunner';
export * from './validation';
/**
* A simple function which throws an error, when a theoretically unreachable code path is executed anyway.
* @param _never An optional parameter which can be used by the client code to ensura that a variable
* has type `never`.
*/
export declare function assertUnreachable(_never?: never): never;
/**
* The type of validation result.
*/
export declare type ValidationResult = Error | undefined;
/**
* The type of a validator.
*/
export declare type Validator<T> = (target: T) => ValidationResult;
/**
* Throws the specified `error`, if defined.
*/
export declare function throwError(error: Error | undefined): void;
/**
* Validates `target` using the specified `validators` and
* returns the first encountered `Error`, or `undefined`.
*/
export declare const validate: <T>(validators: Validator<T>[]) => (target: T) => Error | undefined;
/**
* Keeps only public properties.

@@ -17,2 +40,26 @@ * See https://github.com/Microsoft/TypeScript/issues/471#issuecomment-381842426

export declare function delay(minDelayMilliseconds?: number): Promise<unknown>;
/**
* Returns a promise which resolves when `emitter` emits `event`.
*/
export declare const whenEvent: (event: string) => (emitter: {
once: (event: string, callback: () => any) => any;
}) => Promise<unknown>;
/**
* Returns a promise which resolves when `emitter` emits `"data"`.
*/
export declare const whenData: (emitter: {
once: (event: string, callback: () => any) => any;
}) => Promise<unknown>;
/**
* Returns a promise which resolves when `emitter` emits `"close"`.
*/
export declare const whenClose: (emitter: {
once: (event: string, callback: () => any) => any;
}) => Promise<unknown>;
/**
* Returns a promise which resolves when `emitter` emits `"error"`.
*/
export declare const whenError: (emitter: {
once: (event: string, callback: () => any) => any;
}) => Promise<unknown>;
export declare function randomInteger(minInclusive: number, maxExclusive: number): number;

@@ -19,0 +66,0 @@ /**

import { createAssertError } from './error';
/**
* A simple function which throws an error, when a theoretically unreachable code path is executed anyway.
* @param _never An optional parameter which can be used by the client code to ensura that a variable
* has type `never`.
*/
export function assertUnreachable(_never) {
throw createAssertError('This should never happen!');
}
/**
* Throws the specified `error`, if defined.
*/
export function throwError(error) {
if (error) {
throw error;
}
}
/**
* Validates `target` using the specified `validators` and
* returns the first encountered `Error`, or `undefined`.
*/
export const validate = (validators) => (target) => {
for (let i = 0, l = validators.length; i < l; ++i) {
const error = validators[i](target);
if (error) {
return error;
}
}
return;
};
export function noop() {

@@ -17,2 +46,18 @@ // Do nothing.

}
/**
* Returns a promise which resolves when `emitter` emits `event`.
*/
export const whenEvent = (event) => (emitter) => new Promise(resolve => emitter.once(event, resolve));
/**
* Returns a promise which resolves when `emitter` emits `"data"`.
*/
export const whenData = whenEvent('data');
/**
* Returns a promise which resolves when `emitter` emits `"close"`.
*/
export const whenClose = whenEvent('close');
/**
* Returns a promise which resolves when `emitter` emits `"error"`.
*/
export const whenError = whenEvent('error');
export function randomInteger(minInclusive, maxExclusive) {

@@ -19,0 +64,0 @@ assert(Number.isSafeInteger(minInclusive), 'Argument "minInclusive" must be a safe integer.');

{
"name": "@syncot/util",
"version": "0.0.10",
"version": "0.0.11",
"description": "A collection of utilities required by other @syncot modules.",

@@ -34,3 +34,3 @@ "keywords": [

},
"gitHead": "5c7ad0bf43495567d9fc857718802b7ea52d37bb"
"gitHead": "70a5ae5f5ddb507b3b7ced84f0e0a591f25db627"
}
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