@drunkcod/argis 0.0.9 → 0.0.10

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.
@@ -34,8 +34,12 @@ export declare function argNotNil<T, K extends keyof T>(x: T, key: K): asserts x
34
34
  };
35
35
  export declare function hasOwn<T extends object, K extends PropertyKey>(x: T, key: K): x is T & WithKey<K>;
36
36
  export declare function hasOwn<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
37
+ export declare function hasKey<T extends object, K extends PropertyKey>(x: T, key: K): x is T & WithKey<K>;
38
+ export declare function hasKey<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
37
39
  export declare function assertOwn<T extends object, K extends PropertyKey>(x: T, key: K): asserts x is T & WithKey<K>;
38
40
  export declare function assertOwn<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): asserts x is T & WithKey<K, V>;
41
+ export declare function assertKey<T extends object, K extends PropertyKey>(x: T, key: K): asserts x is T & WithKey<K>;
42
+ export declare function assertKey<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): asserts x is T & WithKey<K, V>;
39
43
  export declare function nullIfEmpty<T extends {
40
44
  length: number;
41
45
  }>(x: T | null): T | null;
package/lib/cjs/index.js CHANGED
@@ -6,7 +6,9 @@ exports.isNotNil = isNotNil;
6
6
  exports.assertNotNil = assertNotNil;
7
7
  exports.argNotNil = argNotNil;
8
8
  exports.hasOwn = hasOwn;
9
+ exports.hasKey = hasKey;
9
10
  exports.assertOwn = assertOwn;
11
+ exports.assertKey = assertKey;
10
12
  exports.nullIfEmpty = nullIfEmpty;
11
13
  exports.intOrUndefined = intOrUndefined;
12
14
  exports.omit = omit;
@@ -46,9 +48,18 @@ function _hasOwn(x, key) {
46
48
  function hasOwn(x, key, ofType) {
47
49
  return _hasOwn(x, key) && (ofType == undefined || ofType(x[key]));
48
50
  }
51
+ function _hasKey(x, key) {
52
+ return key in x;
53
+ }
54
+ function hasKey(x, key, ofType) {
55
+ return _hasKey(x, key) && (ofType == undefined || ofType(x[key]));
56
+ }
49
57
  function assertOwn(x, key, ofType) {
50
58
  (ofType ? hasOwn(x, key, ofType) : hasOwn(x, key)) || ArgumentError.missing({ key });
51
59
  }
60
+ function assertKey(x, key, ofType) {
61
+ (ofType ? hasKey(x, key, ofType) : hasKey(x, key)) || ArgumentError.missing({ key });
62
+ }
52
63
  function nullIfEmpty(x) {
53
64
  return x == null || x.length == 0 ? null : x;
54
65
  }
package/lib/index.d.ts CHANGED
@@ -34,8 +34,12 @@ export declare function argNotNil<T, K extends keyof T>(x: T, key: K): asserts x
34
34
  };
35
35
  export declare function hasOwn<T extends object, K extends PropertyKey>(x: T, key: K): x is T & WithKey<K>;
36
36
  export declare function hasOwn<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
37
+ export declare function hasKey<T extends object, K extends PropertyKey>(x: T, key: K): x is T & WithKey<K>;
38
+ export declare function hasKey<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
37
39
  export declare function assertOwn<T extends object, K extends PropertyKey>(x: T, key: K): asserts x is T & WithKey<K>;
38
40
  export declare function assertOwn<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): asserts x is T & WithKey<K, V>;
41
+ export declare function assertKey<T extends object, K extends PropertyKey>(x: T, key: K): asserts x is T & WithKey<K>;
42
+ export declare function assertKey<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): asserts x is T & WithKey<K, V>;
39
43
  export declare function nullIfEmpty<T extends {
40
44
  length: number;
41
45
  }>(x: T | null): T | null;
package/lib/index.js CHANGED
@@ -32,9 +32,18 @@ function _hasOwn(x, key) {
32
32
  export function hasOwn(x, key, ofType) {
33
33
  return _hasOwn(x, key) && (ofType == undefined || ofType(x[key]));
34
34
  }
35
+ function _hasKey(x, key) {
36
+ return key in x;
37
+ }
38
+ export function hasKey(x, key, ofType) {
39
+ return _hasKey(x, key) && (ofType == undefined || ofType(x[key]));
40
+ }
35
41
  export function assertOwn(x, key, ofType) {
36
42
  (ofType ? hasOwn(x, key, ofType) : hasOwn(x, key)) || ArgumentError.missing({ key });
37
43
  }
44
+ export function assertKey(x, key, ofType) {
45
+ (ofType ? hasKey(x, key, ofType) : hasKey(x, key)) || ArgumentError.missing({ key });
46
+ }
38
47
  export function nullIfEmpty(x) {
39
48
  return x == null || x.length == 0 ? null : x;
40
49
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@drunkcod/argis",
3
3
  "type": "module",
4
- "version": "0.0.9",
4
+ "version": "0.0.10",
5
5
  "description": "Tiny method arg checking with strong types.",
6
6
  "scripts": {
7
7
  "clean": "rimraf lib",