@oliversalzburg/js-utils 0.0.24-dev.12 → 0.0.24-dev.14

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 (4) hide show
  1. package/nil.d.ts +19 -8
  2. package/nil.js +28 -11
  3. package/nil.js.map +1 -1
  4. package/package.json +1 -1
package/nil.d.ts CHANGED
@@ -45,7 +45,7 @@ export declare class UnexpectedNilError extends Error {
45
45
  }
46
46
  /**
47
47
  * Ensure that the passed subject is not nil; throw otherwise.
48
- * @param subject - A subject that is possible nil.
48
+ * @param subject - A subject that is possibly nil.
49
49
  * @param errorMessage - An optional error message to throw when the subject is nil.
50
50
  * @typeParam TSubject - The type of the subject.
51
51
  * @returns The subject, if it isn't nil.
@@ -54,15 +54,16 @@ export declare class UnexpectedNilError extends Error {
54
54
  */
55
55
  export declare function mustExist<TSubject>(subject: Maybe<TSubject>, errorMessage?: string): TSubject;
56
56
  /**
57
- * Ensure that the passed subject is not nil; throw otherwise.
58
- * @param subject - A subject that is possible nil.
59
- * @param errorMessage - An optional error message to throw when the subject is nil.
60
- * @typeParam TSubject - The type of the subject.
61
- * @returns The subject, if it isn't nil.
62
- * @throws {@linkcode UnexpectedNilError} When the subject is nil.
57
+ * Ensure that all passed subjects are not nil; throw otherwise.
58
+ * @param subjects - The subjects that are possibly nil.
59
+ * @param errorMessage - An optional error message to throw when a subject is nil.
60
+ * @typeParam TSubject - The type a the subject.
61
+ * @returns The subjects, if they aren't nil.
62
+ * @throws {@linkcode UnexpectedNilError} When a subject is nil.
63
63
  * @group Nullability
64
+ * @group Array
64
65
  */
65
- export declare function mustExistAll<TSubject>(subject: Array<Maybe<TSubject>>, errorMessage?: string): Array<TSubject>;
66
+ export declare function mustExistAll<TSubject>(subjects: Array<Maybe<TSubject>>, errorMessage?: string): Array<TSubject>;
66
67
  /**
67
68
  * Ensure that the passed subject is not nil; throw otherwise.
68
69
  * @param subject - A subject that is possibly nil.
@@ -71,6 +72,15 @@ export declare function mustExistAll<TSubject>(subject: Array<Maybe<TSubject>>,
71
72
  * @group Nullability
72
73
  */
73
74
  export declare function assertExists<TSubject>(subject: Maybe<TSubject>): asserts subject is TSubject;
75
+ /**
76
+ * Ensure that the passed subjects are not nil; throw otherwise.
77
+ * @param subjects - Subjects that are possibly nil.
78
+ * @typeParam TSubject - The type of a subject.
79
+ * @throws {@linkcode UnexpectedNilError} When a subject is nil.
80
+ * @group Nullability
81
+ * @group Array
82
+ */
83
+ export declare function assertExistsAll<TSubject>(subjects: Array<Maybe<TSubject>>): asserts subjects is Array<TSubject>;
74
84
  /**
75
85
  * Convert a nilable into a real value, if it is nil.
76
86
  * @param nilable - The subject to convert to an optional.
@@ -85,6 +95,7 @@ export declare function coalesce<T>(nilable: Maybe<T>, to: T): T;
85
95
  * @param to - The value to coalese to.
86
96
  * @returns An array with where all values are not nil.
87
97
  * @group Nullability
98
+ * @group Array
88
99
  */
89
100
  export declare function coalesceArray<T>(nilables: Array<Maybe<T>>, to?: Maybe<T>): Array<T>;
90
101
  /**
package/nil.js CHANGED
@@ -38,7 +38,7 @@ export class UnexpectedNilError extends Error {
38
38
  }
39
39
  /**
40
40
  * Ensure that the passed subject is not nil; throw otherwise.
41
- * @param subject - A subject that is possible nil.
41
+ * @param subject - A subject that is possibly nil.
42
42
  * @param errorMessage - An optional error message to throw when the subject is nil.
43
43
  * @typeParam TSubject - The type of the subject.
44
44
  * @returns The subject, if it isn't nil.
@@ -52,21 +52,22 @@ export function mustExist(subject, errorMessage) {
52
52
  return subject;
53
53
  }
54
54
  /**
55
- * Ensure that the passed subject is not nil; throw otherwise.
56
- * @param subject - A subject that is possible nil.
57
- * @param errorMessage - An optional error message to throw when the subject is nil.
58
- * @typeParam TSubject - The type of the subject.
59
- * @returns The subject, if it isn't nil.
60
- * @throws {@linkcode UnexpectedNilError} When the subject is nil.
55
+ * Ensure that all passed subjects are not nil; throw otherwise.
56
+ * @param subjects - The subjects that are possibly nil.
57
+ * @param errorMessage - An optional error message to throw when a subject is nil.
58
+ * @typeParam TSubject - The type a the subject.
59
+ * @returns The subjects, if they aren't nil.
60
+ * @throws {@linkcode UnexpectedNilError} When a subject is nil.
61
61
  * @group Nullability
62
+ * @group Array
62
63
  */
63
- export function mustExistAll(subject, errorMessage) {
64
- for (const element of subject) {
65
- if (isNil(element)) {
64
+ export function mustExistAll(subjects, errorMessage) {
65
+ for (const subject of subjects) {
66
+ if (isNil(subject)) {
66
67
  throw new UnexpectedNilError(errorMessage);
67
68
  }
68
69
  }
69
- return subject;
70
+ return subjects;
70
71
  }
71
72
  /**
72
73
  * Ensure that the passed subject is not nil; throw otherwise.
@@ -80,6 +81,21 @@ export function assertExists(subject) {
80
81
  throw new UnexpectedNilError();
81
82
  }
82
83
  }
84
+ /**
85
+ * Ensure that the passed subjects are not nil; throw otherwise.
86
+ * @param subjects - Subjects that are possibly nil.
87
+ * @typeParam TSubject - The type of a subject.
88
+ * @throws {@linkcode UnexpectedNilError} When a subject is nil.
89
+ * @group Nullability
90
+ * @group Array
91
+ */
92
+ export function assertExistsAll(subjects) {
93
+ for (const subject of subjects) {
94
+ if (isNil(subject)) {
95
+ throw new UnexpectedNilError();
96
+ }
97
+ }
98
+ }
83
99
  /**
84
100
  * Convert a nilable into a real value, if it is nil.
85
101
  * @param nilable - The subject to convert to an optional.
@@ -99,6 +115,7 @@ export function coalesce(nilable, to) {
99
115
  * @param to - The value to coalese to.
100
116
  * @returns An array with where all values are not nil.
101
117
  * @group Nullability
118
+ * @group Array
102
119
  */
103
120
  export function coalesceArray(nilables, to) {
104
121
  const result = new Array();
package/nil.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"nil.js","sourceRoot":"","sources":["../source/nil.ts"],"names":[],"mappings":"AAgBA;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CAAW,OAAwB;IACtD,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AACnD,CAAC;AAED;;;;;;;;;GASG;AACH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AClB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAI,OAAiB;IAC7C,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACnB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@oliversalzburg/js-utils",
4
- "version": "0.0.24-dev.12",
4
+ "version": "0.0.24-dev.14",
5
5
  "license": "MIT",
6
6
  "author": "Oliver Salzburg <oliver.salzburg@gmail.com>",
7
7
  "repository": {