cno-bedrock 0.0.2 → 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/CHANGELOG.md CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.0.4](https://github.com/Anadian/cno-bedrock/compare/v0.0.3...v0.0.4) (2025-11-07)
6
+
7
+
8
+ ### Chores
9
+
10
+ * Hotfix to synchronise pnpm lock file with package.jsom. ([ec65486](https://github.com/Anadian/cno-bedrock/commit/ec65486ca54176871edb583e30db5bdd7cfcf50d))
11
+
12
+ ### [0.0.3](https://github.com/Anadian/cno-bedrock/compare/v0.0.2...v0.0.3) (2025-11-07)
13
+
14
+
15
+ ### Features
16
+
17
+ * Improved asserts. ([cf088d7](https://github.com/Anadian/cno-bedrock/commit/cf088d7edc21fe04a02a66d12ab7aaeed259fe3a))
18
+
19
+
20
+ ### Continuous Integration
21
+
22
+ * Added new tests and coverage. ([3b95166](https://github.com/Anadian/cno-bedrock/commit/3b95166a247af1fcd1ae5734423abd8ad432fbfe))
23
+
24
+
25
+ ### Documentation
26
+
27
+ * Fixed README ([dcb0971](https://github.com/Anadian/cno-bedrock/commit/dcb09711b1c6b6d08350ebd3a8c360712251c302))
28
+ * Updated for v0.0.3 ([1f99373](https://github.com/Anadian/cno-bedrock/commit/1f99373f51395c65aa65b632e22eb770e7b629de))
29
+
30
+
31
+ ### Chores
32
+
33
+ * Updated deps. ([5769701](https://github.com/Anadian/cno-bedrock/commit/57697015fec19b5b667faf43497bd949afa17af2))
34
+
5
35
  ### [0.0.2](https://github.com/Anadian/cno-bedrock/compare/v0.0.1...v0.0.2) (2025-09-15)
6
36
 
7
37
 
package/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
  # Install
20
20
  Available on the [npm registry](https://www.npmjs.com/package/cno-bedrock) as `cno-bedrock`. Add it to a project using [pnpm](https://pnpm.io/cli/add):
21
21
  ```sh
22
- pnpm add --save cno-read-by-block
22
+ pnpm add --save cno-bedrock
23
23
  ```
24
24
  It can, of course, also be installed by [npm](https://docs.npmjs.com/cli/v8/commands/npm-install) or [yarn](https://yarnpkg.com/getting-started/usage) using the normal methods.
25
25
  # Usage
@@ -36,7 +36,6 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
36
36
  | --- | --- | --- |
37
37
  | actual | any | The actual value. |
38
38
  | expected | any | The expected value. |
39
- | message | string | A custom message for the assertion. \[default: ''\] |
40
39
 
41
40
  #### Throws
42
41
  | code | type | condition |
@@ -46,6 +45,7 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
46
45
  #### History
47
46
  | version | change |
48
47
  | --- | --- |
48
+ | 0.0.3 | Removed message parametre. |
49
49
  | 0.0.1 | WIP |
50
50
 
51
51
 
@@ -57,7 +57,6 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
57
57
  | --- | --- | --- |
58
58
  | actual | any | The actual value. |
59
59
  | expected | any | The expected value. |
60
- | message, | string | A custom message for the assertion. \[default: ''\] |
61
60
 
62
61
  #### Throws
63
62
  | code | type | condition |
@@ -67,9 +66,67 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
67
66
  #### History
68
67
  | version | change |
69
68
  | --- | --- |
69
+ | 0.0.3 | Redone |
70
70
  | 0.0.1 | WIP |
71
71
 
72
72
 
73
+ ### assertIsEmpty
74
+ > Throws if `actual` is not empty.
75
+
76
+ #### Parametres
77
+ | name | type | description |
78
+ | --- | --- | --- |
79
+ | actual | any | The actual value. |
80
+
81
+ #### Throws
82
+ | code | type | condition |
83
+ | --- | --- | --- |
84
+ | 'ERR_ASSERTION_ISEMPTY' | AssertionError | Thrown if `actual` is not empty. |
85
+
86
+ #### History
87
+ | version | change |
88
+ | --- | --- |
89
+ | 0.0.3 | WIP |
90
+
91
+
92
+ ### assertIsNullOrUndefined
93
+ > Throws if `actual` is neither `null` nor `undefined`.
94
+
95
+ #### Parametres
96
+ | name | type | description |
97
+ | --- | --- | --- |
98
+ | actual | any | The actual value. |
99
+
100
+ #### Throws
101
+ | code | type | condition |
102
+ | --- | --- | --- |
103
+ | 'ERR_ASSERTION_ISNULLORUNDEFINED' | AssertionError | Thrown if `actual` is neither `null` nor `undefined`. |
104
+
105
+ #### History
106
+ | version | change |
107
+ | --- | --- |
108
+ | 0.0.3 | WIP |
109
+
110
+
111
+ ### assertIsNullOrEmpty
112
+ > Throws if `actual` is neither an empty string, `null`, nor `undefined`.
113
+
114
+ #### Parametres
115
+ | name | type | description |
116
+ | --- | --- | --- |
117
+ | actual | any | The actual value. |
118
+
119
+ #### Throws
120
+ | code | type | condition |
121
+ | --- | --- | --- |
122
+ | 'ERR_ASSERTION_ISNULLOREMPTY' | AssertionError | Thrown if `actual` is neither an empty string, `null`, nor `undefined`. |
123
+
124
+ #### History
125
+ | version | change |
126
+ | --- | --- |
127
+ | 0.0.3 | WIP |
128
+
129
+
73
130
  ### assertStrictlyNotEqual
74
131
  > Throws if actual is not the same type as expected or is the value as expected.
75
132
 
@@ -78,10 +135,9 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
78
135
  | --- | --- | --- |
79
136
  | actual | any | The actual value. |
80
137
  | expected | any | The expected/invalid value. |
81
- | name | string | The name of variable as a string, for a more informative auto message. \[default: ''\] |
82
- | value | string | The expected value as a string, for a more informative auto message. \[default: ''\] |
83
- | expectedType | string | The expected's type as a string, for a more informative auto message. \[default: ''\] |
84
- | message | string | A custom message for the assertion. \[default: ''\] |
138
+ | name | string | The name of variable as a string, for a more informative auto message. \[default: `null`\] |
139
+ | value | string | The expected value as a string, for a more informative auto message. \[default: `null`\] |
140
+ | expectedType | string | The expected's type as a string, for a more informative auto message. \[default: `null`\] |
85
141
 
86
142
  #### Throws
87
143
  | code | type | condition |
@@ -91,6 +147,7 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
91
147
  #### History
92
148
  | version | change |
93
149
  | --- | --- |
150
+ | 0.0.3 | Removed message parametre. |
94
151
  | 0.0.1 | WIP |
95
152
 
96
153
 
@@ -102,7 +159,6 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
102
159
  | --- | --- | --- |
103
160
  | actual | any | The actual value. |
104
161
  | expected | any | The expected value. |
105
- | message | string | A custom message for the assertion. \[default: ''\] |
106
162
 
107
163
  #### Throws
108
164
  | code | type | condition |
@@ -112,6 +168,7 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
112
168
  #### History
113
169
  | version | change |
114
170
  | --- | --- |
171
+ | 0.0.3 | Removed message parametre. |
115
172
  | 0.0.1 | WIP |
116
173
 
117
174
 
@@ -123,7 +180,6 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
123
180
  | --- | --- | --- |
124
181
  | actual | any | The actual error. |
125
182
  | expected | any | An object with a the properties 'constructor' with the constructor function used to create the error and 'code' the expected code property of the error. |
126
- | message | string | A custom message for the assertion. \[default: ''\] |
127
183
 
128
184
  #### Throws
129
185
  | code | type | condition |
@@ -137,14 +193,13 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
137
193
 
138
194
 
139
195
  ### assertObjectsQuantitativelyEqual
140
- > Throws if acutal doesn't have the same properties and values as expected. Compared via [lodash's `_.isEqual`](https://lodash.com/docs/4.17.15#isEqual).
196
+ > Throws if actual doesn't have the same properties and values as expected. Compared via [lodash's `_.isEqual`](https://lodash.com/docs/4.17.15#isEqual).
141
197
 
142
198
  #### Parametres
143
199
  | name | type | description |
144
200
  | --- | --- | --- |
145
201
  | actual | any | The actual object. |
146
202
  | expected | any | The expected object. |
147
- | message | string | A custom message for the assertion. \[default: ''\] |
148
203
 
149
204
  #### Throws
150
205
  | code | type | condition |
@@ -154,5 +209,26 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
154
209
  #### History
155
210
  | version | change |
156
211
  | --- | --- |
212
+ | 0.0.3 | Removed message parametre. |
213
+ | 0.0.1 | WIP |
214
+
215
+
216
+ ### assertNullOrFunction
217
+ > Throws if actual is neither `null` nor a function.
218
+
219
+ #### Parametres
220
+ | name | type | description |
221
+ | --- | --- | --- |
222
+ | actual | any | The actual object. |
223
+
224
+ #### Throws
225
+ | code | type | condition |
226
+ | --- | --- | --- |
227
+ | 'ERR_ASSERTION_NULLORFUNCTION' | AssertionError | Thrown if actual is neither `null` nor a function. |
228
+
229
+ #### History
230
+ | version | change |
231
+ | --- | --- |
232
+ | 0.0.3 | Removed message parametre. |
157
233
  | 0.0.1 | WIP |
158
234
 
@@ -121,12 +121,11 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
121
121
  ##### `options` Properties
122
122
  | name | type | default | description |
123
123
  | --- | --- | --- | --- |
124
- | duration | number | Number.NaN | The duration; assumed to be in seconds unless `base` is specified. |
125
- | seconds_per_unit | number | 1 | The base of scale for `duration`; for example: `1` mean duration is specified in seconds, `0.001` means duration is in milliseconds, `60` means duration is in minutes. |
126
- | units_per_second | number | 1 | The inverse of `seconds_per_unit` which can also be used to derive `seconds_per_unit` via taking the reciprocal (1/`units_per_second`); ignored if `seconds_per_unit` is specified. |
127
- | units | string|boolean | "\u205f" | A string to place between a number and its unit or a non-truthy value to omit units entirely from the formatted string. |
128
- | separator | string|boolean | "\u2005" | A string to put between each order of magnitude or a non-truthy value to omit separation altogether. |
129
- | applied_units | object | { hours: 'h', minutes: 'min', seconds: 's' } | An object whose properties indicate which units should be included with the property value indicating a preferred unit symbol. See [MathJS](https://mathjs.org/docs/datatypes/units.html#reference) for available units. |
124
+ | duration | number | Number.NaN | The duration; assumed to be in seconds unless 'duration_unit' is specified. |
125
+ | unit_seperator | string|boolean | "\u205f" | A string to place between a number and its unit or a non-truthy value to omit units entirely from the formatted string. |
126
+ | split_separator | string|boolean | "\u2005" | A string to put between each order of magnitude or a non-truthy value to omit separation altogether. |
127
+ | duration_unit | object\|string | `MathJS.unit('s')` | A valid [MathJS unit object](https://mathjs.org/docs/datatypes/units.html#units) such as the one returned from the `unit` function, or a string to be passed to said function. |
128
+ | split_units | Array | `[ 'h', 'min', 's' ]` | An array to be passed to [`splitUnit`](https://mathjs.org/docs/datatypes/units.html#unitsplitunitparts). See [MathJS](https://mathjs.org/docs/datatypes/units.html#reference) for available units. |
130
129
 
131
130
  #### Returns
132
131
  | type | description |
package/docs/src/lib.md CHANGED
@@ -71,3 +71,22 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
71
71
  | --- | --- |
72
72
  | 0.0.1 | WIP |
73
73
 
74
+
75
+ ### isNullOrEmpty
76
+ > Returns `true` if the a given `input_value` is either an empty string (`''`), `null`, or `undefined`.
77
+
78
+ #### Parametres
79
+ | name | type | description |
80
+ | --- | --- | --- |
81
+ | input_value | string|object | The value to check. |
82
+
83
+ #### Returns
84
+ | type | description |
85
+ | --- | --- |
86
+ | boolean | Returns `true` if `input_value` is an empty string, `null`, or `undefined`; `false` otherwise. |
87
+
88
+ #### History
89
+ | version | change |
90
+ | --- | --- |
91
+ | 0.0.3 | WIP |
92
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cno-bedrock",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Micropackage: a test bed for various small pieces of reusable code.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,6 +20,12 @@
20
20
  },
21
21
  "homepage": "https://github.com/Anadian/cno-bedrock#readme",
22
22
  "keywords": [
23
+ "cno",
24
+ "framework",
25
+ "minimal",
26
+ "essential",
27
+ "micro",
28
+ "micropackage",
23
29
  "libre",
24
30
  "free",
25
31
  "open",
@@ -84,17 +90,17 @@
84
90
  },
85
91
  "devDependencies": {
86
92
  "c8": "^10.1.3",
87
- "eslint": "^9.24.0",
93
+ "eslint": "^9.39.1",
88
94
  "extract-documentation-comments": "^0.4.2",
89
95
  "hjson": "^3.2.2",
90
- "npm-check-updates": "^17.1.18",
96
+ "npm-check-updates": "^19.1.2",
91
97
  "shelljs": "^0.10.0",
92
98
  "standard-version": "^9.5.0"
93
99
  },
94
100
  "dependencies": {
95
101
  "lodash": "^4.17.21",
96
- "mathjs": "^14.5.2",
97
- "nanoid": "^5.1.5"
102
+ "mathjs": "^15.1.0",
103
+ "nanoid": "^5.1.6"
98
104
  },
99
105
  "scripts": {
100
106
  "test": "node --test ./src/lib.test.js",
package/src/cno-assert.js CHANGED
@@ -30,7 +30,7 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
30
30
 
31
31
  //# Dependencies
32
32
  //## Internal
33
- import { annotateThis } from './cno-utility.js'
33
+ import { annotateThis, inspThis } from './cno-utility.js'
34
34
  //## Standard
35
35
  import AssertNS from 'node:assert/strict';
36
36
  //## External
@@ -50,7 +50,6 @@ const FILENAME = 'cno-assert.js';
50
50
  | --- | --- | --- |
51
51
  | actual | any | The actual value. |
52
52
  | expected | any | The expected value. |
53
- | message | string | A custom message for the assertion. \[default: ''\] |
54
53
 
55
54
  #### Throws
56
55
  | code | type | condition |
@@ -60,16 +59,18 @@ const FILENAME = 'cno-assert.js';
60
59
  #### History
61
60
  | version | change |
62
61
  | --- | --- |
62
+ | 0.0.3 | Removed message parametre. |
63
63
  | 0.0.1 | WIP |
64
64
  */
65
- function assertSameType( actual, expected, message = '' ){
65
+ function assertSameType( actual, expected ){
66
66
  // Constants
67
67
  const FUNCTION_NAME = 'assertSameType';
68
68
  // Variables
69
69
  var return_error = null;
70
+ var message = '';
70
71
  // Function
71
72
  if( typeof(actual) !== typeof(expected) ){
72
- message ??= `Type of 'actual' (${typeof(actual)}) is not the same type as 'expected' (${typeof(expected)}).`;
73
+ message = `Type of 'actual' (${typeof(actual)}) is not the same type as 'expected' (${typeof(expected)}).`;
73
74
  return_error = new AssertNS.AssertionError( { message: message, actual: actual, expected: expected, operator: 'SameType' } );
74
75
  return_error.code += '_SAMETYPE';
75
76
  annotateThis.call( return_error );
@@ -85,7 +86,6 @@ function assertSameType( actual, expected, message = '' ){
85
86
  | --- | --- | --- |
86
87
  | actual | any | The actual value. |
87
88
  | expected | any | The expected value. |
88
- | message, | string | A custom message for the assertion. \[default: ''\] |
89
89
 
90
90
  #### Throws
91
91
  | code | type | condition |
@@ -95,16 +95,18 @@ function assertSameType( actual, expected, message = '' ){
95
95
  #### History
96
96
  | version | change |
97
97
  | --- | --- |
98
+ | 0.0.3 | Redone |
98
99
  | 0.0.1 | WIP |
99
100
  */
100
- function assertNonstrictNotEqual( actual, expected, message = '' ){
101
+ function assertNonstrictNotEqual( actual, expected ){
101
102
  // Constants
102
103
  const FUNCTION_NAME = 'assertNonstrictNotEqual';
103
104
  // Variables
104
105
  var return_error = null;
106
+ var message = '';
105
107
  // Function
106
108
  if( actual == expected ){
107
- message ??= `Value of 'actual' (${actual}) is equal to 'expected' (${expected}).`;
109
+ message = `Value of 'actual' (${actual}) is equal to 'expected' (${expected}).`;
108
110
  return_error = new AssertNS.AssertionError( { message: message, actual: actual, expected: expected, operator: 'NonstrictNotEqual' } );
109
111
  return_error.code += '_NONSTRICTNOTEQUAL';
110
112
  annotateThis.call( return_error );
@@ -112,6 +114,110 @@ function assertNonstrictNotEqual( actual, expected, message = '' ){
112
114
  }
113
115
  } // assertNonstrictNotEqual
114
116
  /**
117
+ ### assertIsEmpty
118
+ > Throws if `actual` is not empty.
119
+
120
+ #### Parametres
121
+ | name | type | description |
122
+ | --- | --- | --- |
123
+ | actual | any | The actual value. |
124
+
125
+ #### Throws
126
+ | code | type | condition |
127
+ | --- | --- | --- |
128
+ | 'ERR_ASSERTION_ISEMPTY' | AssertionError | Thrown if `actual` is not empty. |
129
+
130
+ #### History
131
+ | version | change |
132
+ | --- | --- |
133
+ | 0.0.3 | WIP |
134
+ */
135
+ function assertIsEmpty( actual ){
136
+ var return_error = null;
137
+ if( actual.length !== 0 ){
138
+ return_error = new AssertNS.AssertionError( { message: `'actual' (${actual}) has a non-zero length.`, actual: actual, operator: 'IsEmpty' } );
139
+ return_error.code += '_ISEMPTY';
140
+ throw return_error;
141
+ }
142
+ }
143
+ /**
144
+ ### assertIsNullOrUndefined
145
+ > Throws if `actual` is neither `null` nor `undefined`.
146
+
147
+ #### Parametres
148
+ | name | type | description |
149
+ | --- | --- | --- |
150
+ | actual | any | The actual value. |
151
+
152
+ #### Throws
153
+ | code | type | condition |
154
+ | --- | --- | --- |
155
+ | 'ERR_ASSERTION_ISNULLORUNDEFINED' | AssertionError | Thrown if `actual` is neither `null` nor `undefined`. |
156
+
157
+ #### History
158
+ | version | change |
159
+ | --- | --- |
160
+ | 0.0.3 | WIP |
161
+ */
162
+ function assertIsNullOrUndefined( actual ){
163
+ var return_error = null;
164
+ if( actual !== null && actual !== undefined ){
165
+ return_error = new AssertNS.AssertionError( { message: `'actual' (${actual}) is neither null nor undefined.`, actual: actual, operator: 'IsNullOrUndefined' } );
166
+ return_error.code += '_ISNULLORUNDEFINED';
167
+ throw return_error;
168
+ }
169
+ }
170
+ /**
171
+ ### assertIsNullOrEmpty
172
+ > Throws if `actual` is neither an empty string, `null`, nor `undefined`.
173
+
174
+ #### Parametres
175
+ | name | type | description |
176
+ | --- | --- | --- |
177
+ | actual | any | The actual value. |
178
+
179
+ #### Throws
180
+ | code | type | condition |
181
+ | --- | --- | --- |
182
+ | 'ERR_ASSERTION_ISNULLOREMPTY' | AssertionError | Thrown if `actual` is neither an empty string, `null`, nor `undefined`. |
183
+
184
+ #### History
185
+ | version | change |
186
+ | --- | --- |
187
+ | 0.0.3 | WIP |
188
+ */
189
+ function assertIsNullOrEmpty( actual ){
190
+ // Constants
191
+ const FUNCTION_NAME = 'assertIsNullOrEmpty';
192
+ // Variables
193
+ var return_error = null;
194
+ var cause_error = null;
195
+ var message = '';
196
+ // Function
197
+ if( typeof(actual) === 'string' ){
198
+ try{
199
+ assertIsEmpty( actual );
200
+ } catch( error ){
201
+ cause_error = error;
202
+ message = `'actual' (${actual}) is a non-empty string.`;
203
+ }
204
+ } else{
205
+ try{
206
+ assertIsNullOrUndefined( actual );
207
+ } catch( error ){
208
+ cause_error = error;
209
+ message = cause_error.message;
210
+ }
211
+ }
212
+ if( cause_error ){
213
+ return_error = new AssertNS.AssertionError( { message: message, actual: actual, operator: 'IsNullOrEmpty' } );
214
+ return_error.cause = cause_error;
215
+ return_error.code += '_ISNULLOREMPTY';
216
+ annotateThis.call( return_error );
217
+ throw return_error;
218
+ }
219
+ } // assertIsNullOrEmpty
220
+ /**
115
221
  ### assertStrictlyNotEqual
116
222
  > Throws if actual is not the same type as expected or is the value as expected.
117
223
 
@@ -120,10 +226,9 @@ function assertNonstrictNotEqual( actual, expected, message = '' ){
120
226
  | --- | --- | --- |
121
227
  | actual | any | The actual value. |
122
228
  | expected | any | The expected/invalid value. |
123
- | name | string | The name of variable as a string, for a more informative auto message. \[default: ''\] |
124
- | value | string | The expected value as a string, for a more informative auto message. \[default: ''\] |
125
- | expectedType | string | The expected's type as a string, for a more informative auto message. \[default: ''\] |
126
- | message | string | A custom message for the assertion. \[default: ''\] |
229
+ | name | string | The name of variable as a string, for a more informative auto message. \[default: `null`\] |
230
+ | value | string | The expected value as a string, for a more informative auto message. \[default: `null`\] |
231
+ | expectedType | string | The expected's type as a string, for a more informative auto message. \[default: `null`\] |
127
232
 
128
233
  #### Throws
129
234
  | code | type | condition |
@@ -133,14 +238,16 @@ function assertNonstrictNotEqual( actual, expected, message = '' ){
133
238
  #### History
134
239
  | version | change |
135
240
  | --- | --- |
241
+ | 0.0.3 | Removed message parametre. |
136
242
  | 0.0.1 | WIP |
137
243
  */
138
- function assertStrictlyNotEqual( actual, expected, name = '', value = '', expectedType = '', message = '' ){
244
+ function assertStrictlyNotEqual( actual, expected, name, value, expectedType ){
139
245
  // Constants
140
246
  const FUNCTION_NAME = 'assertStrictlyNotEqual';
141
247
  // Variables
142
248
  var return_error = null;
143
249
  var cause_error = null;
250
+ var message = '';
144
251
  // Function
145
252
  try{
146
253
  assertSameType( actual, expected );
@@ -148,17 +255,18 @@ function assertStrictlyNotEqual( actual, expected, name = '', value = '', expect
148
255
  assertNonstrictNotEqual( actual, expected );
149
256
  } catch( error ){
150
257
  cause_error = error;
151
- message ??= `${name ?? 'Value'} must not be equal to ${value ?? expected}.`;
258
+ message = `${name ?? 'Value'} must not be equal to ${value ?? expected}.`;
152
259
  }
153
260
  } catch( error ){
154
261
  cause_error = error;
155
- message ??= `${name ?? 'Type of \'actual\''} must be the same type as ${value ?? expected} (${expectedType ?? typeof(expected)}).`;
262
+ message = `${name ?? 'Type of \'actual\''} must be the same type as ${value ?? expected} (${expectedType ?? typeof(expected)}).`;
156
263
  }
157
264
  if( cause_error ){
158
265
  return_error = new AssertNS.AssertionError( { message: message, actual: actual, expected: expected, operator: 'StrictlyNotEqual' } );
159
266
  return_error.code += '_STRICTLYNOTEQUAL';
160
267
  return_error.cause = cause_error;
161
268
  annotateThis.call( return_error );
269
+ //return_error.toString = return_error.insp;
162
270
  throw return_error;
163
271
  }
164
272
  } // assertStrictlyNotEqual
@@ -171,7 +279,6 @@ function assertStrictlyNotEqual( actual, expected, name = '', value = '', expect
171
279
  | --- | --- | --- |
172
280
  | actual | any | The actual value. |
173
281
  | expected | any | The expected value. |
174
- | message | string | A custom message for the assertion. \[default: ''\] |
175
282
 
176
283
  #### Throws
177
284
  | code | type | condition |
@@ -181,16 +288,18 @@ function assertStrictlyNotEqual( actual, expected, name = '', value = '', expect
181
288
  #### History
182
289
  | version | change |
183
290
  | --- | --- |
291
+ | 0.0.3 | Removed message parametre. |
184
292
  | 0.0.1 | WIP |
185
293
  */
186
- function assertInstanceof( actual, expected, message = '' ){
294
+ function assertInstanceof( actual, expected ){
187
295
  // Constants
188
296
  const FUNCTION_NAME = 'assertInstanceof';
189
297
  // Variables
190
298
  var return_error = null;
299
+ var message = '';
191
300
  // Function
192
301
  if( !( actual instanceof expected ) ){
193
- message ??= `${variable_name ?? 'Actual'} is not an instance of ${constructor_name ?? 'expected'}.`;
302
+ message = `'actual' (${actual}) is not an instance of 'expected'.`;
194
303
  return_error = new AssertNS.AssertionError( { message: message, actual: actual, expected: expected, operator: 'Instanceof' } );
195
304
  return_error.code += '_INSTANCEOF';
196
305
  annotateThis.call( return_error );
@@ -206,7 +315,6 @@ function assertInstanceof( actual, expected, message = '' ){
206
315
  | --- | --- | --- |
207
316
  | actual | any | The actual error. |
208
317
  | expected | any | An object with a the properties 'constructor' with the constructor function used to create the error and 'code' the expected code property of the error. |
209
- | message | string | A custom message for the assertion. \[default: ''\] |
210
318
 
211
319
  #### Throws
212
320
  | code | type | condition |
@@ -218,7 +326,7 @@ function assertInstanceof( actual, expected, message = '' ){
218
326
  | --- | --- |
219
327
  | 0.0.1 | WIP |
220
328
  */
221
- function assertExpectedError( actual, expected, message = '' ){
329
+ function assertExpectedError( actual, expected ){
222
330
  // Constants
223
331
  const FUNCTION_NAME = 'assertExpectedError';
224
332
  // Variables
@@ -252,7 +360,6 @@ function assertExpectedError( actual, expected, message = '' ){
252
360
  | --- | --- | --- |
253
361
  | actual | any | The actual object. |
254
362
  | expected | any | The expected object. |
255
- | message | string | A custom message for the assertion. \[default: ''\] |
256
363
 
257
364
  #### Throws
258
365
  | code | type | condition |
@@ -262,17 +369,19 @@ function assertExpectedError( actual, expected, message = '' ){
262
369
  #### History
263
370
  | version | change |
264
371
  | --- | --- |
372
+ | 0.0.3 | Removed message parametre. |
265
373
  | 0.0.1 | WIP |
266
374
  */
267
- function assertObjectsQuantitativelyEqual( actual, expected, message = '' ){
375
+ function assertObjectsQuantitativelyEqual( actual, expected ){
268
376
 
269
377
  // Constants
270
378
  const FUNCTION_NAME = 'assertObjectsQuantitativelyEqual';
271
379
  // Variables
272
380
  var return_error = null;
381
+ var message = '';
273
382
  // Function
274
383
  if( !_.isEqual( actual, expected ) ){
275
- message ??= `'actual' object (${inspThis.call( actual )}) doesn't strictly match 'expected' object (${inspThis.call( expected )}).`;
384
+ message = `'actual' object (${inspThis.call( actual )}) doesn't strictly match 'expected' object (${inspThis.call( expected )}).`;
276
385
  return_error = new AssertNS.AssertionError( { message: message, actual: actual, expected: expected, operator: 'ObjectsQuantitativelyEqual' } );
277
386
  return_error.code += '_OBJECTSQUANTITAIVELYEQUAL';
278
387
  annotateThis.call( return_error );
@@ -287,7 +396,6 @@ function assertObjectsQuantitativelyEqual( actual, expected, message = '' ){
287
396
  | name | type | description |
288
397
  | --- | --- | --- |
289
398
  | actual | any | The actual object. |
290
- | message | string | A custom message for the assertion. \[default: ''\] |
291
399
 
292
400
  #### Throws
293
401
  | code | type | condition |
@@ -297,17 +405,19 @@ function assertObjectsQuantitativelyEqual( actual, expected, message = '' ){
297
405
  #### History
298
406
  | version | change |
299
407
  | --- | --- |
408
+ | 0.0.3 | Removed message parametre. |
300
409
  | 0.0.1 | WIP |
301
410
  */
302
- function assertNullOrFunction( actual, message = '' ){
411
+ function assertNullOrFunction( actual ){
303
412
  // Constants
304
413
  const FUNCTION_NAME = 'assertNullOrFunction';
305
414
  // Variables
306
415
  var return_error = null;
416
+ var message = '';
307
417
  // Function
308
418
  if( actual != null && typeof(actual) !== 'function' ){
309
- message ??= `'actual' (${inspThis.call( actual )}) is neither null nor a function.`;
310
- return_error = new AssertNS.AssertionError( { message: message, actual: actual, expected: expected, operator: 'NullOrFunction' } );
419
+ message = `'actual' (${inspThis.call( actual )}) is neither null nor a function.`;
420
+ return_error = new AssertNS.AssertionError( { message: message, actual: actual, operator: 'NullOrFunction' } );
311
421
  return_error.code += '_NULLORFUNCTION';
312
422
  annotateThis.call( return_error );
313
423
  throw return_error;
@@ -324,6 +434,18 @@ Object.defineProperties( NAMESPACE, {
324
434
  value: assertNonstrictNotEqual,
325
435
  enumerable: true
326
436
  },
437
+ assertIsEmpty: {
438
+ value: assertIsEmpty,
439
+ enumerable: true
440
+ },
441
+ assertIsNullOrUndefined: {
442
+ value: assertIsNullOrUndefined,
443
+ enumerable: true
444
+ },
445
+ assertIsNullOrEmpty: {
446
+ value: assertIsNullOrEmpty,
447
+ enumerable: true
448
+ },
327
449
  assertStrictlyNotEqual: {
328
450
  value: assertStrictlyNotEqual,
329
451
  enumerable: true
package/src/lib.js CHANGED
@@ -131,6 +131,47 @@ function isStrictlyNotEqual( input_options = {} ){
131
131
  this?.logger?.log({file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `returned: ${_return}`});
132
132
  return _return;
133
133
  } // isStrictlyNotEqual
134
+ /**
135
+ ### isNullOrEmpty
136
+ > Returns `true` if the a given `input_value` is either an empty string (`''`), `null`, or `undefined`.
137
+
138
+ #### Parametres
139
+ | name | type | description |
140
+ | --- | --- | --- |
141
+ | input_value | string|object | The value to check. |
142
+
143
+ #### Returns
144
+ | type | description |
145
+ | --- | --- |
146
+ | boolean | Returns `true` if `input_value` is an empty string, `null`, or `undefined`; `false` otherwise. |
147
+
148
+ #### History
149
+ | version | change |
150
+ | --- | --- |
151
+ | 0.0.3 | WIP |
152
+ */
153
+ function isNullOrEmpty( input_value ){
154
+ const FUNCTION_NAME = 'isNullOrEmpty';
155
+ // Variables
156
+ //var arguments_array = Array.from(arguments);
157
+ var _return = false;
158
+ var return_error = null;
159
+ this?.logger?.log({file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `received: ${input_value}`});
160
+ // Parametre checks
161
+ try{
162
+ this?.logger?.log( 'Begin try' );
163
+ Assert.assertIsNullOrEmpty( input_value );
164
+ _return = true;
165
+ this?.logger?.log( 'End try' );
166
+ } catch( error ){
167
+ this?.logger?.log( 'Begin catch: %o', error );
168
+ _return = false;
169
+ this?.logger?.log( 'End catch' );
170
+ }
171
+ // Return
172
+ this?.logger?.log({file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `returned: ${_return}`});
173
+ return _return;
174
+ } // isNullOrEmpty
134
175
 
135
176
  // Exports
136
177
 
@@ -159,10 +200,14 @@ Object.defineProperties( NAMESPACE, {
159
200
  isStrictlyNotEqual: {
160
201
  value: isStrictlyNotEqual,
161
202
  enumerable: true
203
+ },
204
+ isNullOrEmpty: {
205
+ value: isNullOrEmpty,
206
+ enumerable: true
162
207
  }
163
208
  } );
164
209
 
165
- export { NAMESPACE as default, isStrictlyNotEqual };
210
+ export { NAMESPACE as default, isStrictlyNotEqual, isNullOrEmpty };
166
211
  export * from './cno-time.js';
167
212
  export * from './cno-utility.js';
168
213
  export * from './cno-noop.js';
package/src/lib.test.js CHANGED
@@ -149,6 +149,49 @@ function main_test(){
149
149
  } catch( error ){
150
150
  Bedrock.assert.assertExpectedError( error, { constructor: TypeError, code: 'ERR_INVALID_ARG_TYPE' } );
151
151
  }
152
+ // v0.0.3
153
+ Bedrock.assert.assertIsEmpty( [] );
154
+ try{
155
+ Bedrock.assert.assertIsEmpty( 'Not empty.' );
156
+ } catch( error ){
157
+ //console.log( error );
158
+ Bedrock.assert.assertExpectedError( error, { constructor: AssertionError, code: 'ERR_ASSERTION_ISEMPTY' } );
159
+ }
160
+ Bedrock.assert.assertIsNullOrUndefined( null );
161
+ try{
162
+ Bedrock.assert.assertIsNullOrUndefined( 'Not empty.' );
163
+ } catch( error ){
164
+ //console.log( error );
165
+ Bedrock.assert.assertExpectedError( error, { constructor: AssertionError, code: 'ERR_ASSERTION_ISNULLORUNDEFINED' } );
166
+ }
167
+ Bedrock.assert.assertIsNullOrEmpty( '' );
168
+ Bedrock.assert.assertIsNullOrEmpty( null );
169
+ try{
170
+ Bedrock.assert.assertIsNullOrEmpty( 'Not empty.' );
171
+ } catch( error ){
172
+ //console.log( error );
173
+ Bedrock.assert.assertExpectedError( error, { constructor: AssertionError, code: 'ERR_ASSERTION_ISNULLOREMPTY' } );
174
+ }
175
+ try{
176
+ Bedrock.assert.assertIsNullOrEmpty( 1 );
177
+ } catch( error ){
178
+ //console.log( error );
179
+ Bedrock.assert.assertExpectedError( error, { constructor: AssertionError, code: 'ERR_ASSERTION_ISNULLOREMPTY' } );
180
+ }
181
+ Bedrock.assert.assertNullOrFunction( Bedrock.noop.returnNull );
182
+ Bedrock.assert.assertNullOrFunction( null );
183
+ try{
184
+ Bedrock.assert.assertNullOrFunction( 1 );
185
+ } catch( error ){
186
+ //console.log( error );
187
+ Bedrock.assert.assertExpectedError( error, { constructor: AssertionError, code: 'ERR_ASSERTION_NULLORFUNCTION' } );
188
+ }
189
+ var e = Bedrock.isNullOrEmpty( '' );
190
+ var n = Bedrock.isNullOrEmpty( null );
191
+ var f = Bedrock.isNullOrEmpty( '0' );
192
+ if( e !== true || n !== true || f !== false ){
193
+ console.error( 'Something is wrong!', e, n, f );
194
+ }
152
195
  }
153
196
  main_test();
154
197