@drunkcod/argis 0.0.4 → 0.0.5

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.
Files changed (2) hide show
  1. package/lib/index.js +9 -21
  2. package/package.json +6 -2
package/lib/index.js CHANGED
@@ -1,15 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArgumentError = void 0;
4
- exports.isNil = isNil;
5
- exports.isNotNil = isNotNil;
6
- exports.assertNotNil = assertNotNil;
7
- exports.argNotNil = argNotNil;
8
- exports.hasOwn = hasOwn;
9
- exports.assertOwn = assertOwn;
10
- exports.nullIfEmpty = nullIfEmpty;
11
- exports.intOrUndefined = intOrUndefined;
12
- class ArgumentError extends Error {
1
+ export class ArgumentError extends Error {
13
2
  constructor(message) {
14
3
  super(message);
15
4
  }
@@ -24,30 +13,29 @@ class ArgumentError extends Error {
24
13
  throw e;
25
14
  }
26
15
  }
27
- exports.ArgumentError = ArgumentError;
28
- function isNil(x, key) {
16
+ export function isNil(x, key) {
29
17
  return x == null || (key !== undefined && x[key] == null);
30
18
  }
31
- function isNotNil(x, key) {
19
+ export function isNotNil(x, key) {
32
20
  return !isNil(x) && (key === undefined || !isNil(x[key]));
33
21
  }
34
- function assertNotNil(x) {
22
+ export function assertNotNil(x) {
35
23
  if (x == null)
36
24
  ArgumentError.null('Unexpected null');
37
25
  }
38
- function argNotNil(x, key) {
26
+ export function argNotNil(x, key) {
39
27
  isNotNil(x, key) || ArgumentError.null(`'${String(key)}' was null or undefined`);
40
28
  }
41
- function hasOwn(x, key) {
29
+ export function hasOwn(x, key) {
42
30
  return Object.hasOwn(x, key);
43
31
  }
44
- function assertOwn(x, key) {
32
+ export function assertOwn(x, key) {
45
33
  hasOwn(x, key) || ArgumentError.missing({ key });
46
34
  }
47
- function nullIfEmpty(x) {
35
+ export function nullIfEmpty(x) {
48
36
  return x == null || x.length == 0 ? null : x;
49
37
  }
50
- function intOrUndefined(x) {
38
+ export function intOrUndefined(x) {
51
39
  if (isNil(x))
52
40
  return undefined;
53
41
  const v = Number.parseInt(x);
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@drunkcod/argis",
3
- "version": "0.0.4",
3
+ "type": "module",
4
+ "version": "0.0.5",
4
5
  "description": "Tiny method arg checking with strong types.",
5
6
  "scripts": {
6
- "build": "rimraf lib && tsc",
7
+ "clean": "rimraf lib",
8
+ "compile": "tsc",
9
+ "build": "npm-run-all clean compile --silent",
7
10
  "test": "jest"
8
11
  },
9
12
  "author": "Tobbe Gyllebring",
@@ -17,6 +20,7 @@
17
20
  "devDependencies": {
18
21
  "@jest/globals": "^29.7.0",
19
22
  "jest": "^29.7.0",
23
+ "npm-run-all": "^4.1.5",
20
24
  "rimraf": "^6.0.1",
21
25
  "ts-jest": "^29.2.5",
22
26
  "typescript": "^5.5.4"