@drunkcod/argis 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ type NoNullMembers<T> = {
2
+ [P in keyof T]: NonNullable<T[P]>;
3
+ };
4
+ export type WithRequired<T, K extends keyof T> = Required<NoNullMembers<Pick<T, K>>> & Omit<T, K>;
5
+ export declare class ArgumentError extends Error {
6
+ constructor(message: string);
7
+ static null(message: string): void;
8
+ }
9
+ export declare function isNotNil<T, K extends keyof T>(x: T, key: K): x is T & {
10
+ [P in K]-?: NonNullable<T[K]>;
11
+ };
12
+ export declare function argNotNil<T, K extends keyof T>(x: T, key: K): asserts x is T & {
13
+ [P in K]-?: NonNullable<T[K]>;
14
+ };
15
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArgumentError = void 0;
4
+ exports.isNotNil = isNotNil;
5
+ exports.argNotNil = argNotNil;
6
+ class ArgumentError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ }
10
+ static null(message) {
11
+ const e = new ArgumentError(message);
12
+ e.name = 'ArgumentNullError';
13
+ throw e;
14
+ }
15
+ }
16
+ exports.ArgumentError = ArgumentError;
17
+ function isNotNil(x, key) {
18
+ const v = x[key];
19
+ return v !== undefined && v !== null;
20
+ }
21
+ ;
22
+ function argNotNil(x, key) {
23
+ isNotNil(x, key) || ArgumentError.null(`'${String(key)}' was null or undefined`);
24
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@drunkcod/argis",
3
+ "version": "0.0.1",
4
+ "description": "Tiny method arg checking with strong types.",
5
+ "scripts": {
6
+ "build": "rimraf lib && tsc",
7
+ "test": "jest"
8
+ },
9
+ "author": "Tobbe Gyllebring",
10
+ "license": "MIT",
11
+ "main": "./lib/index.js",
12
+ "types": "./lib/index.d.ts",
13
+ "files": [
14
+ "lib/**/*"
15
+ ],
16
+ "devDependencies": {
17
+ "@jest/globals": "^29.7.0",
18
+ "jest": "^29.7.0",
19
+ "rimraf": "^6.0.1",
20
+ "ts-jest": "^29.2.5",
21
+ "typescript": "^5.5.4"
22
+ }
23
+ }