@drunkcod/argis 0.0.3 → 0.0.4

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 CHANGED
@@ -24,4 +24,8 @@ export declare function argNotNil<T, K extends keyof T>(x: T, key: K): asserts x
24
24
  };
25
25
  export declare function hasOwn<T extends object, K extends PropertyKey>(x: T, key: K): x is T & WithKey<K>;
26
26
  export declare function assertOwn<T extends object, K extends PropertyKey>(x: T, key: K): asserts x is T & WithKey<K>;
27
+ export declare function nullIfEmpty<T extends {
28
+ length: number;
29
+ }>(x: T | null): T | null;
30
+ export declare function intOrUndefined(x?: string | null): number | undefined;
27
31
  export {};
package/lib/index.js CHANGED
@@ -7,6 +7,8 @@ exports.assertNotNil = assertNotNil;
7
7
  exports.argNotNil = argNotNil;
8
8
  exports.hasOwn = hasOwn;
9
9
  exports.assertOwn = assertOwn;
10
+ exports.nullIfEmpty = nullIfEmpty;
11
+ exports.intOrUndefined = intOrUndefined;
10
12
  class ArgumentError extends Error {
11
13
  constructor(message) {
12
14
  super(message);
@@ -42,3 +44,12 @@ function hasOwn(x, key) {
42
44
  function assertOwn(x, key) {
43
45
  hasOwn(x, key) || ArgumentError.missing({ key });
44
46
  }
47
+ function nullIfEmpty(x) {
48
+ return x == null || x.length == 0 ? null : x;
49
+ }
50
+ function intOrUndefined(x) {
51
+ if (isNil(x))
52
+ return undefined;
53
+ const v = Number.parseInt(x);
54
+ return Number.isNaN(v) ? undefined : v;
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drunkcod/argis",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Tiny method arg checking with strong types.",
5
5
  "scripts": {
6
6
  "build": "rimraf lib && tsc",