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

@litert/core

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@litert/core - npm Package Compare versions

Comparing version 0.7.1 to 1.0.0

lib/class.RawPromise.d.ts.map

5

CHANGES.md
# Changes Logs
## v1.0.0
- The first feature stable version.
- Added full documents in Simplified Chinese.
## v0.7.1

@@ -4,0 +9,0 @@

7

lib/class.RawPromise.d.ts

@@ -36,3 +36,3 @@ /**

*/
reject: IPromiseRejector<E>;
reject(e: E): void;
/**

@@ -43,3 +43,3 @@ * The Promise resolver method.

*/
resolve: IPromiseResolver<T>;
resolve(data?: T): void;
/**

@@ -49,3 +49,6 @@ * The Promise object.

promise: Promise<T>;
protected _resolve: IPromiseResolver<T>;
protected _reject: IPromiseRejector<E>;
constructor();
}
//# sourceMappingURL=class.RawPromise.d.ts.map

@@ -27,8 +27,24 @@ "use strict";

this.promise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
this._resolve = resolve;
this._reject = reject;
});
}
/**
* The Promise rejector method.
*
* If this method is called, promise will be REJECTED.
*/
reject(e) {
return this._reject(e);
}
/**
* The Promise resolver method.
*
* If this method is called, promise will be RESOLVED.
*/
resolve(data) {
return this._resolve(data);
}
}
exports.RawPromise = RawPromise;
//# sourceMappingURL=class.RawPromise.js.map

@@ -16,13 +16,25 @@ /**

*/
import { IPromiseRejector, IPromiseResolver } from "./class.RawPromise";
export interface IPromiseTimeoutResultHandler<T, E> {
(e: E): void;
(e: null, v: T): void;
}
export declare class TimeoutPromise<T = any, E = Error> {
import { RawPromise } from "./class.RawPromise";
export declare type ITimeoutResult<T, E> = {
"error": null;
"value"?: T;
} | {
"error": E;
"value": void;
};
export declare type IPromiseTimeoutResultHandler<T, E> = (result: ITimeoutResult<T, E>) => void;
export declare class TimeoutPromise<T = any, E = Error> extends RawPromise<T, E> {
private _timer;
private _msTimeout;
private _timeoutError;
private _handleTimeout;
/**
* The Promise object.
* The constructor of a timeout-promise.
*
* @param msTimeout The timeout in milliseconds.
* @param timeoutError The error object to be thrown if timeout
* @param autoStart Start the timer immediately.
* @param handleTimeout Inject a handler to receiver the result after timeout.
*/
promise: Promise<T>;
private _timer;
constructor(msTimeout: number, timeoutError: E, autoStart?: boolean, handleTimeout?: IPromiseTimeoutResultHandler<T, E>);
/**

@@ -35,3 +47,3 @@ * The Promise rejector method.

*/
reject: IPromiseRejector<E>;
reject(e: E): void;
/**

@@ -44,16 +56,4 @@ * The Promise resolver method.

*/
resolve: IPromiseResolver<T>;
private _msTimeout;
private _timeoutError;
private _handleTimeout;
resolve(data?: T): void;
/**
* The constructor of a timeout-promise.
*
* @param msTimeout The timeout in milliseconds.
* @param timeoutError The error object to be thrown if timeout
* @param autoStart Start the timer immediately.
* @param handleTimeout Inject a handler to receiver the result after timeout.
*/
constructor(msTimeout: number, timeoutError: E, autoStart?: boolean, handleTimeout?: IPromiseTimeoutResultHandler<T, E>);
/**
* Start the timer.

@@ -63,1 +63,2 @@ */

}
//# sourceMappingURL=class.TimeoutPromise.d.ts.map

@@ -18,3 +18,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class TimeoutPromise {
const class_RawPromise_1 = require("./class.RawPromise");
class TimeoutPromise extends class_RawPromise_1.RawPromise {
/**

@@ -29,2 +30,3 @@ * The constructor of a timeout-promise.

constructor(msTimeout, timeoutError, autoStart = true, handleTimeout) {
super();
this._msTimeout = msTimeout;

@@ -35,37 +37,51 @@ this._timeoutError = timeoutError;

}
this.promise = new Promise((resolve, reject) => {
if (autoStart) {
this.start();
}
this.resolve = (data) => {
/**
* If no timer, it means already timeout, so do nothing.
*/
if (null === this._timer) {
if (this._handleTimeout) {
this._handleTimeout(null, data);
}
return;
}
clearTimeout(this._timer);
this._timer = null;
resolve(data);
};
this.reject = (error) => {
/**
* If no timer, it means already timeout, so do nothing.
*/
if (null === this._timer) {
if (this._handleTimeout) {
this._handleTimeout(error);
}
return;
}
clearTimeout(this._timer);
this._timer = null;
reject(error);
};
});
if (autoStart) {
this.start();
}
}
/**
* The Promise rejector method.
*
* If this method is called, promise will be REJECTED.
*
* If it's already timeont, then do nothing.
*/
reject(e) {
/**
* If no timer, it means already timeout, so do nothing.
*/
if (null === this._timer) {
this._handleTimeout && this._handleTimeout({
"error": e,
"value": undefined
});
return;
}
clearTimeout(this._timer);
this._timer = null;
this._reject(e);
}
/**
* The Promise resolver method.
*
* If this method is called, promise will be RESOLVED.
*
* If it's already timeont, then do nothing.
*/
resolve(data) {
/**
* If no timer, it means already timeout, so do nothing.
*/
if (null === this._timer) {
this._handleTimeout && this._handleTimeout({
"error": null,
"value": data
});
return;
}
clearTimeout(this._timer);
this._timer = null;
this._resolve(data);
}
/**
* Start the timer.

@@ -76,3 +92,3 @@ */

this._timer = setTimeout(() => {
this.reject(this._timeoutError);
this._reject(this._timeoutError);
/**

@@ -79,0 +95,0 @@ * Remove the timer when timeout.

@@ -16,6 +16,7 @@ /**

*/
export declare type DefaultMetadataType = Record<string, any>;
/**
* Describe the basic information of an error.
*/
export interface IErrorPayload {
export interface IErrorData<M extends {}> {
/**

@@ -36,4 +37,11 @@ * The numeric-code of an error, used to identify the type or the reason

message: string;
/**
* The metadata of error.
*/
metadata: M;
}
export interface IErrorData extends IErrorPayload {
/**
* Describe the full information of an error.
*/
export interface IErrorFullData<M extends {}> extends IErrorData<M> {
/**

@@ -44,3 +52,6 @@ * The calling-stack of the position where the error occurred.

}
export interface IError {
/**
* The LiteRT standard error objects.
*/
export interface IError<M extends {} = DefaultMetadataType> {
/**

@@ -66,2 +77,6 @@ * The numeric-code of an error, used to identify the type or the reason

/**
* The metadata of error.
*/
readonly metadata: M;
/**
* Get the calling-stack as a string array.

@@ -77,20 +92,43 @@ */

*/
toJSON(withStack?: false): IErrorPayload;
toJSON(withStack: true): IErrorData;
toJSON(withStack?: false): IErrorData<M>;
toJSON(withStack: true): IErrorFullData<M>;
}
export interface IErrorConstructor {
new (message?: string): IError;
name: string;
message: string;
code: number;
/**
* The constructor of error objects.
*/
export interface IErrorConstructor<M extends {}> {
/**
* The constructor of the objects of the error.
*/
new (opts?: {
message?: string;
metadata?: M;
}): IError<M>;
/**
* The name of the error.
*/
readonly name: string;
/**
* The default description of the error.
*/
readonly message: string;
/**
* The code of the error.
*/
readonly code: number;
}
export interface IErrorHub {
/**
* A hub of errors, is a collection and factory of error types.
*
* Every hub has a standalone namespace of error types.
*/
export interface IErrorHub<M extends {}> {
/**
* Define a new error type.
*
* @param code The unique numeric-identity for the new error type.
* @param name The unique string-identity for the new error type.
* @param message The description for the new error type.
* @param code The unique numeric-identity for the new error type.
* @param name The unique string-identity for the new error type.
* @param message The description for the new error type.
*/
define(code: number, name: string, message: string): IErrorConstructor;
define<M2 extends M = M>(code: number, name: string, message: string): IErrorConstructor<M2>;
/**

@@ -101,3 +139,3 @@ * Get the error constructor by its name .

*/
get(name: string): IErrorConstructor;
get<M2 extends M = M>(name: string): IErrorConstructor<M2>;
/**

@@ -109,6 +147,25 @@ * Check if an error belongs to an error type defined in this hub.

*/
is(e: IError, id?: string): boolean;
is<M2 extends M = M>(e: any, id?: string | number): e is IError<M2>;
/**
* Check if an error belongs to an error type defined in this hub.
*
* @param e The error to be checked.
* @param id The name or code of error type to be checked.
*/
is(e: any, id?: string | number): e is IError<M>;
}
export declare function createErrorHub(): IErrorHub;
export declare function getDefaultErrorHub(): IErrorHub;
export declare function isError(e: any): e is IError;
/**
* Create a new error hub that has a standalone namespace of error types.
*/
export declare function createErrorHub<M extends {}>(): IErrorHub<M>;
/**
* Get the default hub of errors.
*/
export declare function getDefaultErrorHub(): IErrorHub<DefaultMetadataType>;
/**
* Check if an object is a LiteRT error object.
*
* @param e The error object to be identified.
*/
export declare function isError<M extends {} = DefaultMetadataType>(e: any): e is IError<M>;
//# sourceMappingURL=Error.d.ts.map

@@ -36,2 +36,7 @@ "use strict";

"value": message
},
"metadata": {
"writable": false,
"configurable": false,
"value": metadata || {}
}

@@ -50,3 +55,3 @@ });

}
let ret = Function("code", "name", "message", THE_CONSTRUCTOR);
let ret = Function("code", "name", "message", "metadata", THE_CONSTRUCTOR);
ret.prototype.getStackAsArray = function () {

@@ -57,10 +62,12 @@ return this.stack.split(/\n\s+at /).slice(1);

return withStack ? {
"code": this.code,
"name": this.name,
"code": this.code,
"message": this.message,
"metadata": this.metadata,
"stack": this.getStackAsArray()
} : {
"code": this.code,
"name": this.name,
"code": this.code,
"message": this.message
"message": this.message,
"metadata": this.metadata
};

@@ -79,7 +86,8 @@ };

this._baseError = (Function("BaseError", `class __ extends BaseError {
constructor(code, name, message) {
constructor(code, name, message, metadata) {
super(
code,
name,
message
message,
metadata
);

@@ -91,3 +99,3 @@ };

is(e, id) {
if (id) {
if (typeof id !== "undefined") {
return (!!this._errors[id]) && (e instanceof this._errors[id]);

@@ -113,7 +121,8 @@ }

return this._errors[code] = this._errors[name] = (Function("BaseError", `class ${name} extends BaseError {
constructor(message) {
constructor(opts = {}) {
super(
${code},
${JSON.stringify(name)},
message || ${JSON.stringify(message)}
opts.message || ${JSON.stringify(message)},
opts.metadata
);

@@ -134,3 +143,3 @@ };

},
"code": {
"message": {
"writable": false,

@@ -148,2 +157,5 @@ "configurable": false,

}
/**
* Create a new error hub that has a standalone namespace of error types.
*/
function createErrorHub() {

@@ -154,2 +166,5 @@ return new ErrorHub();

const DEFAULT_HUB = createErrorHub();
/**
* Get the default hub of errors.
*/
function getDefaultErrorHub() {

@@ -159,2 +174,7 @@ return DEFAULT_HUB;

exports.getDefaultErrorHub = getDefaultErrorHub;
/**
* Check if an object is a LiteRT error object.
*
* @param e The error object to be identified.
*/
function isError(e) {

@@ -161,0 +181,0 @@ return e instanceof BaseError;

@@ -17,38 +17,5 @@ /**

/**
* The template type of dictionary.
*
* @deprecated Duplicated, use `Record` instead. This will be removed in v1.0.0.
*/
export interface Dict<T> {
[key: string]: T;
}
/**
* The template type of dictionary.
*
* @deprecated Use `Dict` instead. This will be removed in v1.0.0.
*/
export declare type IDictionary<T> = Dict<T>;
/**
* Semantically stressing an nullable type.
*/
export declare type Nullable<T> = T | null;
/**
* Semantically stressing an optional type.
*
* @deprecated Useless. This will be removed in v1.0.0.
*/
export declare type Optional<T> = T | undefined;
/**
* The signature of decorator for classes.
*
* @deprecated Duplicated. This will be removed in v1.0.0.
*/
export declare type ClassDecorator = (target: Function) => void;
/**
* The signature of decorator for methods.
*
* @deprecated Duplicated. This will be removed in v1.0.0.
*/
export declare type MethodDecorator = (target: Object, property: string | symbol) => void;
export * from "./class.Exception";
export * from "./class.RawPromise";

@@ -60,1 +27,2 @@ export * from "./class.TimeoutPromise";

export { Async, Validators };
//# sourceMappingURL=index.d.ts.map

@@ -21,3 +21,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./class.Exception"));
__export(require("./class.RawPromise"));

@@ -24,0 +23,0 @@ __export(require("./class.TimeoutPromise"));

@@ -28,6 +28,6 @@ /**

*
* @param ms Milliseconds to wait
* @param arg The result of promise resolved.
* @param ms Milliseconds to wait
* @param args The result of promise resolved.
*/
export declare function sleep(ms: number, arg?: any): Promise<any[]>;
export declare function sleep(ms: number, ...args: any[]): Promise<any[]>;
/**

@@ -43,1 +43,2 @@ * Call the function after 0ms.

export declare function multiTasks<T, E>(tasks: Array<Promise<T>>): Promise<Array<IWaitResult<T, E>>>;
//# sourceMappingURL=utilities.async.d.ts.map

@@ -23,7 +23,7 @@ "use strict";

*
* @param ms Milliseconds to wait
* @param arg The result of promise resolved.
* @param ms Milliseconds to wait
* @param args The result of promise resolved.
*/
function sleep(ms, arg) {
return new Promise((resolve) => setTimeout(resolve, ms, arg));
function sleep(ms, ...args) {
return new Promise((resolve) => setTimeout(resolve, ms, args));
}

@@ -45,18 +45,19 @@ exports.sleep = sleep;

return new Promise(function (resolve) {
let ret = [];
for (let p of tasks) {
p.then(function (r) {
ret.push({
let ret = Array(tasks.length);
let done = 0;
for (let i = 0; i < tasks.length; i++) {
tasks[i].then(function (r) {
ret[i] = {
success: true,
result: r
});
if (ret.length === tasks.length) {
};
if (++done === tasks.length) {
setTimeout(resolve, 0, ret);
}
}).catch(function (e) {
ret.push({
ret[i] = {
success: false,
result: e
});
if (ret.length === tasks.length) {
};
if (++done === tasks.length) {
setTimeout(resolve, 0, ret);

@@ -63,0 +64,0 @@ }

@@ -25,3 +25,3 @@ /**

*
* Not exactly matches the RFC, but for most usage.
* Not exactly matches the RFC, but fits most general usage.
*

@@ -31,1 +31,2 @@ * @param email The string to be validated.

export declare function isEMailAddress(email: string): boolean;
//# sourceMappingURL=utilities.validators.d.ts.map

@@ -35,3 +35,3 @@ "use strict";

*
* Not exactly matches the RFC, but for most usage.
* Not exactly matches the RFC, but fits most general usage.
*

@@ -41,8 +41,9 @@ * @param email The string to be validated.

function isEMailAddress(email) {
return email.length < EMAIL_MAX_LENGTH &&
EMAIL_REGEXP.test(email) &&
return email.length > 0 &&
email.length < EMAIL_MAX_LENGTH &&
email.indexOf("..") === -1 &&
email.indexOf(".@") === -1;
email.indexOf(".@") === -1 &&
EMAIL_REGEXP.test(email);
}
exports.isEMailAddress = isEMailAddress;
//# sourceMappingURL=utilities.validators.js.map
{
"name": "@litert/core",
"version": "0.7.1",
"version": "1.0.0",
"description": "The core of LiteRT.",

@@ -9,5 +9,6 @@ "main": "lib/index.js",

"build": "echo Using TypeScript && tsc -v && tsc -p .",
"build-watch": "echo Using TypeScript && tsc -v && tsc -w -p .",
"rebuild": "npm run clean && npm run lint && npm run build",
"test": "echo See directory sources/samples",
"clean": "rm -rf dist",
"clean": "rm -rf lib samples",
"lint": "tslint -p . -c tslint.json"

@@ -33,4 +34,4 @@ },

"devDependencies": {
"typescript": "^3.1.2"
"typescript": "^3.1.4"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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