New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@oliversalzburg/js-utils

Package Overview
Dependencies
Maintainers
1
Versions
872
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oliversalzburg/js-utils - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

coverage/base.css

19

output/core.d.ts
/**
* Describes a function that is a constructor for T.
*/
export type ConstructorOf<T = Record<string, unknown>> = new (...args: any[]) => T;
export type ConstructorOf<T = Record<string, unknown>> = new (...args: Array<any>) => T;
/**
* Describes literally any function.
*/
export type AnyFunction = (...args: Array<any>) => any;
/**
* Any constructor
*/
export type AnyConstructor = new (...args: Array<any>) => any;
/**
* Describes a function returning an instance of T.
*/
export type FunctionReturning<T = any> = (...args: Array<any>) => T;
/**
* Describes a class "mixin", which is a function that returns a dynamically
* constructed class, based on the passed parameters.
*/
export type Mixin<T extends FunctionReturning> = InstanceType<ReturnType<T>>;

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

/* eslint-disable @typescript-eslint/no-explicit-any */
export {};
//# sourceMappingURL=core.js.map

2

output/error-serializer.d.ts

@@ -9,3 +9,3 @@ import { AbstractError } from "./errors/AbstractError.js";

* @param subject The object to inspect.
* @returns `true` if the subject is an `Error`, `false´ otherwise.
* @returns `true` if the subject is an `Error`, `false` otherwise.
*/

@@ -12,0 +12,0 @@ export declare const isError: (subject: unknown) => subject is Error;

@@ -8,3 +8,3 @@ import { types } from "node:util";

* @param subject The object to inspect.
* @returns `true` if the subject is an `Error`, `false´ otherwise.
* @returns `true` if the subject is an `Error`, `false` otherwise.
*/

@@ -11,0 +11,0 @@ export const isError = (subject) => {

@@ -27,3 +27,3 @@ import { Maybe } from "../nil.js";

/**
* Constructs a new AbstractError.
* Constructs a new {@link AbstractError}.
* @param code The main identification code for the error.

@@ -34,3 +34,11 @@ * @param message The main error message.

constructor(code: string, message: string, status: number);
/**
* Checks if an object is an instance of {@link AbstractError}, or one of its subclasses.
* @param error The object to check.
* @param allowForeignModule Only check for similar looking error codes.
* You're going to want to use this if you're dealing with a setup where
* multiple versions of js-utils are loaded.
* @returns `true` if the object is an {@link AbstractError}, `false` otherwise.
*/
static isAbstractError(error: unknown, allowForeignModule?: boolean): error is AbstractError;
}

@@ -26,3 +26,3 @@ /**

/**
* Constructs a new AbstractError.
* Constructs a new {@link AbstractError}.
* @param code The main identification code for the error.

@@ -42,2 +42,10 @@ * @param message The main error message.

}
/**
* Checks if an object is an instance of {@link AbstractError}, or one of its subclasses.
* @param error The object to check.
* @param allowForeignModule Only check for similar looking error codes.
* You're going to want to use this if you're dealing with a setup where
* multiple versions of js-utils are loaded.
* @returns `true` if the object is an {@link AbstractError}, `false` otherwise.
*/
static isAbstractError(error, allowForeignModule = true) {

@@ -47,3 +55,3 @@ if (error instanceof AbstractError) {

}
// When multiple versions of core-models3 are loaded at runtime, the
// When multiple versions of js-utils are loaded at runtime, the
// prototypes of errors don't align. In that case, we just analyze the

@@ -50,0 +58,0 @@ // error code.

@@ -8,3 +8,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `InternalError`.
* Constructs a new {@link InternalError}.
* @param message The main error message.

@@ -14,3 +14,8 @@ * @param status The HTTP status code to return.

constructor(message: string, status?: number);
/**
* Converts an error into an {@link InternalError}.
* @param error The error to convert.
* @returns An {@link InternalError} that represents the given error.
*/
static fromError(error: Error): InternalError;
}

@@ -8,3 +8,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `InternalError`.
* Constructs a new {@link InternalError}.
* @param message The main error message.

@@ -20,2 +20,7 @@ * @param status The HTTP status code to return.

}
/**
* Converts an error into an {@link InternalError}.
* @param error The error to convert.
* @returns An {@link InternalError} that represents the given error.
*/
static fromError(error) {

@@ -22,0 +27,0 @@ // Create a _real_ `InternalError` instance, which we will return later.

@@ -8,3 +8,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `InvalidArgumentError`.
* Constructs a new {@link InvalidArgumentError}.
* @param message The main error message.

@@ -11,0 +11,0 @@ * @param status The HTTP status code to return.

@@ -8,3 +8,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `InvalidArgumentError`.
* Constructs a new {@link InvalidArgumentError}.
* @param message The main error message.

@@ -11,0 +11,0 @@ * @param status The HTTP status code to return.

@@ -8,3 +8,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `InvalidOperationError`.
* Constructs a new {@link InvalidOperationError}.
* @param message The main error message.

@@ -11,0 +11,0 @@ * @param status The HTTP status code to return.

@@ -8,3 +8,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `InvalidOperationError`.
* Constructs a new {@link InvalidOperationError}.
* @param message The main error message.

@@ -11,0 +11,0 @@ * @param status The HTTP status code to return.

@@ -7,3 +7,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `NotImplementedError`.
* Constructs a new {@link NotImplementedError}.
* @param message The main error message.

@@ -10,0 +10,0 @@ * @param status The HTTP status code to return.

@@ -7,3 +7,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `NotImplementedError`.
* Constructs a new {@link NotImplementedError}.
* @param message The main error message.

@@ -10,0 +10,0 @@ * @param status The HTTP status code to return.

@@ -8,3 +8,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `PermissionViolationError`.
* Constructs a new {@link PermissionViolationError}.
* @param message The main error message.

@@ -11,0 +11,0 @@ * @param status The HTTP status code to return.

@@ -8,3 +8,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `PermissionViolationError`.
* Constructs a new {@link PermissionViolationError}.
* @param message The main error message.

@@ -11,0 +11,0 @@ * @param status The HTTP status code to return.

@@ -7,3 +7,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `ResourceConflictError`.
* Constructs a new {@link ResourceConflictError}.
* @param message The main error message.

@@ -10,0 +10,0 @@ * @param status The HTTP status code to return.

@@ -7,3 +7,3 @@ import { AbstractError } from "./AbstractError.js";

/**
* Constructs a new `ResourceConflictError`.
* Constructs a new {@link ResourceConflictError}.
* @param message The main error message.

@@ -10,0 +10,0 @@ * @param status The HTTP status code to return.

@@ -7,7 +7,7 @@ import { AbstractError } from "./AbstractError.js";

* into an `UnknownError`.
* To enrich an `Error`-like object that was caught, use the `InternalError`.
* To enrich an `Error`-like object that was caught, use the {@link InternalError}.
*/
export declare class UnknownError extends AbstractError {
/**
* Constructs a new `UnknownError`.
* Constructs a new {@link UnknownError}.
* @param message The main error message.

@@ -14,0 +14,0 @@ * @param status The HTTP status code to return.

@@ -7,7 +7,7 @@ import { AbstractError } from "./AbstractError.js";

* into an `UnknownError`.
* To enrich an `Error`-like object that was caught, use the `InternalError`.
* To enrich an `Error`-like object that was caught, use the {@link InternalError}.
*/
export class UnknownError extends AbstractError {
/**
* Constructs a new `UnknownError`.
* Constructs a new {@link UnknownError}.
* @param message The main error message.

@@ -14,0 +14,0 @@ * @param status The HTTP status code to return.

export * from "./array.js";
export * from "./core.js";
export * from "./error-serializer.js";
export * from "./errors/index.js";
export * from "./graphics/index.js";
export * from "./math/index.js";
export * from "./nil.js";
export * from "./random.js";
export * from "./sleep.js";
export * from "./string-formatter.js";
export * from "./array.js";
export * from "./core.js";
export * from "./error-serializer.js";
export * from "./errors/index.js";
export * from "./graphics/index.js";
export * from "./math/index.js";
export * from "./nil.js";
export * from "./random.js";
export * from "./sleep.js";
export * from "./string-formatter.js";
//# sourceMappingURL=index.js.map

@@ -12,2 +12,9 @@ import { ConstructorOf } from "./core.js";

/**
* Check if something is nil.
* Can be used as a typeguard.
* @param subject The subject that could be nil.
* @returns `true` if the subject is nil, `false` otherwise.
*/
export declare function isNil<T>(subject: Maybe<T>): subject is Nil;
/**
* Check if something is a concrete value of the given type.

@@ -22,12 +29,9 @@ * Can be used as a typeguard.

/**
* Check if something is nil.
* Can be used as a typeguard.
* @param subject The subject that could be nil.
* @returns `true` if the subject is nil, `false` otherwise.
*/
export declare function isNil<T>(subject: Maybe<T>): subject is Nil;
/**
* Thrown when an unexpected nil value was encountered.
*/
export declare class UnexpectedNilError extends Error {
/**
* Constructs a new {UnexpectedNilError}.
* @param message The error message.
*/
constructor(message?: string);

@@ -38,5 +42,6 @@ }

* @param subject A subject that is possible nil.
* @param errorMessage An optional error message to throw when the subject is nil.
* @returns The subject, if it isn't nil.
* @throws {UnexpectedNilError} When the subject is nil.
*/
export declare function mustExist<T>(subject: Maybe<T>): T;
export declare function mustExist<T>(subject: Maybe<T>, errorMessage?: string): T;
/**
* Check if something is nil.
* Can be used as a typeguard.
* @param subject The subject that could be nil.
* @returns `true` if the subject is nil, `false` otherwise.
*/
export function isNil(subject) {
return subject === null || subject === undefined;
}
/**
* Check if something is a concrete value of the given type.

@@ -13,14 +22,9 @@ * Can be used as a typeguard.

/**
* Check if something is nil.
* Can be used as a typeguard.
* @param subject The subject that could be nil.
* @returns `true` if the subject is nil, `false` otherwise.
*/
export function isNil(subject) {
return subject === null || subject === undefined;
}
/**
* Thrown when an unexpected nil value was encountered.
*/
export class UnexpectedNilError extends Error {
/**
* Constructs a new {UnexpectedNilError}.
* @param message The error message.
*/
constructor(message = "unexpected nil value") {

@@ -33,8 +37,9 @@ super(message);

* @param subject A subject that is possible nil.
* @param errorMessage An optional error message to throw when the subject is nil.
* @returns The subject, if it isn't nil.
* @throws {UnexpectedNilError} When the subject is nil.
*/
export function mustExist(subject) {
export function mustExist(subject, errorMessage) {
if (isNil(subject)) {
throw new UnexpectedNilError();
throw new UnexpectedNilError(errorMessage);
}

@@ -41,0 +46,0 @@ return subject;

{
"$schema": "https://json.schemastore.org/package.json",
"name": "@oliversalzburg/js-utils",
"version": "0.0.4",
"version": "0.0.5",
"license": "MIT",

@@ -20,4 +20,6 @@ "author": "Oliver Salzburg <oliver.salzburg@gmail.com>",

"build:tsc": "tsc",
"lint": "yarn run lint:eslint && yarn run lint:tsc",
"docs:typedoc": "typedoc --plugin typedoc-plugin-markdown",
"lint": "yarn run lint:eslint && yarn run lint:prettier && yarn run lint:tsc",
"lint:eslint": "eslint source ./*js",
"lint:prettier": "prettier --check source ./*js",
"lint:tsc": "tsc --noEmit",

@@ -28,20 +30,33 @@ "npm:publish": "npm publish",

"npm:publish:patch": "npm version patch && npm publish",
"prepack": "yarn run build"
"prepack": "yarn run build",
"test": "node --enable-source-maps $(yarn bin mocha) ./output/*.test.js",
"test:coverage": "c8 --reporter html-spa --reporter text node --enable-source-maps $(yarn bin mocha)",
"test:inspect": "node $(yarn bin mocha) --inspect ./output/*.test.js"
},
"types": "./output/index.d.ts",
"devDependencies": {
"@types/chai": "4.3.9",
"@types/chai-as-promised": "7.1.7",
"@types/eslint": "8.44.6",
"@types/node": "20.8.9",
"@typescript-eslint/eslint-plugin": "6.9.0",
"@typescript-eslint/parser": "6.9.0",
"@types/mocha": "10.0.3",
"@types/node": "20.8.10",
"@types/web": "0.0.119",
"@typescript-eslint/eslint-plugin": "6.9.1",
"@typescript-eslint/parser": "6.9.1",
"c8": "8.0.1",
"chai": "4.3.10",
"chai-as-promised": "7.1.1",
"esbuild": "0.19.5",
"eslint": "8.52.0",
"eslint": "8.53.0",
"eslint-plugin-jsdoc": "46.8.2",
"lint-staged": "15.0.2",
"mocha": "10.2.0",
"prettier": "3.0.3",
"prettier-package-json": "2.8.0",
"prettier-plugin-organize-imports": "3.2.3",
"typedoc": "0.25.3",
"typedoc-plugin-markdown": "3.17.0",
"typescript": "5.2.2"
},
"packageManager": "yarn@4.0.0"
"packageManager": "yarn@4.0.1"
}

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