cno-bedrock 0.0.4 → 0.1.0
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 +38 -0
- package/package.json +116 -116
- package/scripts/generate-docs.js +0 -0
- package/src/cno-assert.js +222 -15
- package/src/cno-assert.test.js +331 -0
- package/src/cno-base64.js +230 -0
- package/src/cno-base64.test.js +262 -0
- package/src/cno-bytes.js +387 -0
- package/src/cno-bytes.test.js +222 -0
- package/src/cno-constants.js +121 -0
- package/src/cno-files.js +2135 -0
- package/src/cno-files.test.js +939 -0
- package/src/cno-math.js +407 -0
- package/src/cno-math.test.js +249 -0
- package/src/cno-noop.js +6 -2
- package/src/cno-options.js +73 -4
- package/src/cno-options.test.js +65 -0
- package/src/cno-sha2-256.js +831 -0
- package/src/cno-sha2-256.test.js +697 -0
- package/src/cno-test-matrix.js +709 -0
- package/src/cno-test-matrix.test.js +199 -0
- package/src/cno-timed-cache-map.js +103 -0
- package/src/cno-timed-cache-map.test.js +113 -0
- package/src/cno-tree.js +365 -0
- package/src/cno-tree.test.js +147 -0
- package/src/cno-utility.js +545 -2
- package/src/cno-utility.test.js +276 -0
- package/src/cno-vector.js +1053 -0
- package/src/cno-vector.test.js +523 -0
- package/src/lib.js +5 -138
- package/src/lib.test.js +19 -7
- package/src/stream-test.js +116 -0
- package/test/big-lorem.txt +29 -0
package/src/cno-options.js
CHANGED
|
@@ -30,7 +30,8 @@ Documentation License: [{
|
|
79
80
|
options = Object.assign( options, deriveOptions.STANDARD_OPTIONS, input_options );
|
|
80
81
|
}
|
|
81
|
-
if( input_options
|
|
82
|
+
if( input_options?.noDefaults !== true && default_options != null ){
|
|
82
83
|
options = Object.assign( options, default_options, input_options );
|
|
83
|
-
if( input_options
|
|
84
|
+
if( input_options?.noDynamic !== true && typeof(dynamic_function) === 'function' && dynamic_function != null ){
|
|
84
85
|
options = Object.assign( options, dynamic_function.call( this, options ), input_options );
|
|
85
86
|
} // noDynamic
|
|
86
87
|
} else{
|
|
87
|
-
options = Object.assign(
|
|
88
|
+
options = Object.assign( options, input_options );
|
|
88
89
|
} // noDefaults
|
|
89
90
|
_return = options;
|
|
91
|
+
// try{
|
|
92
|
+
// deriveOptions.assertOptions( _return );
|
|
93
|
+
// } catch( error ){
|
|
94
|
+
// console.error( 'options=%o error=%o input_options=%o default_options=%o dynamic_function=%o STANDARD_OPTIONS=%o', options, error, input_options, default_options, dynamic_function, deriveOptions.STANDARD_OPTIONS );
|
|
95
|
+
// }
|
|
90
96
|
return _return;
|
|
91
97
|
} // deriveOptions
|
|
98
|
+
deriveOptions.assertOptions = function( options_object ){
|
|
99
|
+
var return_error = null;
|
|
100
|
+
var errors_array = [];
|
|
101
|
+
try{
|
|
102
|
+
assertSameType( options_object, deriveOptions.STANDARD_OPTIONS );
|
|
103
|
+
} catch( error ){
|
|
104
|
+
return_error = new Error( `Given "object" is not an object: ${error}` );
|
|
105
|
+
return_error.cause = error;
|
|
106
|
+
errors_array.push( return_error );
|
|
107
|
+
}
|
|
108
|
+
try{
|
|
109
|
+
assertSameType( options_object.noop, deriveOptions.STANDARD_OPTIONS.noop );
|
|
110
|
+
} catch( error ){
|
|
111
|
+
return_error = new Error( `For property "noop": ${error}` );
|
|
112
|
+
return_error.cause = error;
|
|
113
|
+
errors_array.push( return_error );
|
|
114
|
+
}
|
|
115
|
+
try{
|
|
116
|
+
assertSameType( options_object.noDefaults, deriveOptions.STANDARD_OPTIONS.noDefaults );
|
|
117
|
+
} catch( error ){
|
|
118
|
+
return_error = new Error( `For property "noDefaults": ${error}` );
|
|
119
|
+
return_error.cause = error;
|
|
120
|
+
errors_array.push( return_error );
|
|
121
|
+
}
|
|
122
|
+
try{
|
|
123
|
+
assertSameType( options_object.noDynamic, deriveOptions.STANDARD_OPTIONS.noDynamic );
|
|
124
|
+
} catch( error ){
|
|
125
|
+
return_error = new Error( `For property "noDynamic": ${error}` );
|
|
126
|
+
return_error.cause = error;
|
|
127
|
+
errors_array.push( return_error );
|
|
128
|
+
}
|
|
129
|
+
try{
|
|
130
|
+
assertSameType( options_object.logFunction, deriveOptions.STANDARD_OPTIONS.logFunction );
|
|
131
|
+
} catch( error ){
|
|
132
|
+
return_error = new Error( `For property "logFunction": ${error}` );
|
|
133
|
+
return_error.cause = error;
|
|
134
|
+
errors_array.push( return_error );
|
|
135
|
+
}
|
|
136
|
+
try{
|
|
137
|
+
assertSameType( options_object.validationFunction, deriveOptions.STANDARD_OPTIONS.validationFunction );
|
|
138
|
+
} catch( error ){
|
|
139
|
+
return_error = new Error( `For property "validationFunction": ${error}` );
|
|
140
|
+
return_error.cause = error;
|
|
141
|
+
errors_array.push( return_error );
|
|
142
|
+
}
|
|
143
|
+
if( errors_array.length > 1 ){
|
|
144
|
+
return_error = new AggregateError( errors_array );
|
|
145
|
+
throw return_error;
|
|
146
|
+
} else if( errors_array.length === 1 ){
|
|
147
|
+
return_error = errors_array[0];
|
|
148
|
+
throw return_error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
deriveOptions.isOptions = function( options_object ){
|
|
152
|
+
var _return = false;
|
|
153
|
+
try{
|
|
154
|
+
deriveOptions.assertOptions( options_object );
|
|
155
|
+
_return = true;
|
|
156
|
+
} catch( error ){
|
|
157
|
+
_return = false;
|
|
158
|
+
}
|
|
159
|
+
return _return;
|
|
160
|
+
}
|
|
92
161
|
Object.defineProperties( deriveOptions, {
|
|
93
162
|
STANDARD_OPTIONS: {
|
|
94
163
|
value: {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import deriveOptions from './cno-options.js';
|
|
4
|
+
import TestNS from './cno-test-matrix.js';
|
|
5
|
+
import { assertIsEmpty } from './cno-assert.js';
|
|
6
|
+
|
|
7
|
+
TestNS.test( 'deriveOptions:success', async function( t ){
|
|
8
|
+
t.diagnostic( t.name );
|
|
9
|
+
var tm = new TestNS.TestMatrix( { testContext: t } );
|
|
10
|
+
tm.addFunction( { name: 'deriveOptions', func: deriveOptions } );
|
|
11
|
+
tm.addCondition( {
|
|
12
|
+
name: 'null-all',
|
|
13
|
+
success: true,
|
|
14
|
+
args: [ null ],
|
|
15
|
+
expected: deriveOptions.STANDARD_OPTIONS
|
|
16
|
+
} );
|
|
17
|
+
tm.addCondition( {
|
|
18
|
+
name: 'no-standard-options',
|
|
19
|
+
success: true,
|
|
20
|
+
args: [ null, null, null, false ],
|
|
21
|
+
expected: ( return_value ) => {
|
|
22
|
+
var _return = false;
|
|
23
|
+
assertIsEmpty( return_value );
|
|
24
|
+
_return = true;
|
|
25
|
+
return _return;
|
|
26
|
+
}
|
|
27
|
+
} );
|
|
28
|
+
tm.addCondition( {
|
|
29
|
+
name: 'noDefaults-customvalue',
|
|
30
|
+
success: true,
|
|
31
|
+
args: [ { noDefaults: 'customFromInput' }, null, null, true ],
|
|
32
|
+
expected: { ...deriveOptions.STANDARD_OPTIONS, noDefaults: 'customFromInput' }
|
|
33
|
+
} );
|
|
34
|
+
tm.addCondition( {
|
|
35
|
+
name: 'noDynamic-customvalueFromDefaults',
|
|
36
|
+
success: true,
|
|
37
|
+
args: [ { noDefaults: 'customFromInput' }, { noDynamic: 'customFromDefaults' }, null, true ],
|
|
38
|
+
expected: { ...deriveOptions.STANDARD_OPTIONS, noDefaults: 'customFromInput', noDynamic: 'customFromDefaults' }
|
|
39
|
+
} );
|
|
40
|
+
tm.addCondition( {
|
|
41
|
+
name: 'dynamicDefaults',
|
|
42
|
+
success: true,
|
|
43
|
+
args: [ { noDefaults: 'customFromInput' }, { noDynamic: 'customFromDefaults' }, ( options ) => {
|
|
44
|
+
return { ...options, noop: 'customFromDynamic' };
|
|
45
|
+
}, true ],
|
|
46
|
+
expected: { ...deriveOptions.STANDARD_OPTIONS, noDefaults: 'customFromInput', noDynamic: 'customFromDefaults', noop: 'customFromDynamic' }
|
|
47
|
+
} );
|
|
48
|
+
await tm.run();
|
|
49
|
+
tm.conditionsMap.clear();
|
|
50
|
+
tm.functionsMap.clear();
|
|
51
|
+
tm.addFunction( { name: 'isOptions', func: deriveOptions.isOptions } );
|
|
52
|
+
tm.addCondition( {
|
|
53
|
+
name: 'success',
|
|
54
|
+
success: true,
|
|
55
|
+
args: [ deriveOptions.STANDARD_OPTIONS ],
|
|
56
|
+
expected: true
|
|
57
|
+
} );
|
|
58
|
+
tm.addCondition( {
|
|
59
|
+
name: 'failure',
|
|
60
|
+
success: true,
|
|
61
|
+
args: [ false ],
|
|
62
|
+
expected: false
|
|
63
|
+
} );
|
|
64
|
+
await tm.run();
|
|
65
|
+
} );
|