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
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
# [cno-bytes.test.js](src/cno-bytes.test.js)
|
|
4
|
+
> Tests for [cno-bytes](src/cno-bytes.js).
|
|
5
|
+
|
|
6
|
+
Author: Anadian
|
|
7
|
+
|
|
8
|
+
Code license: MIT
|
|
9
|
+
```
|
|
10
|
+
Copyright 2026 Anadian
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
12
|
+
software and associated documentation files (the "Software"), to deal in the Software
|
|
13
|
+
without restriction, including without limitation the rights to use, copy, modify,
|
|
14
|
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
15
|
+
permit persons to whom the Software is furnished to do so, subject to the following
|
|
16
|
+
conditions:
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all copies
|
|
18
|
+
or substantial portions of the Software.
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
20
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
21
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
22
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
23
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
24
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
```
|
|
26
|
+
Documentation License: [](http://creativecommons.org/licenses/by-sa/4.0/)
|
|
27
|
+
> The source-code comments and documentation are written in [GitHub Flavored Markdown](https://github.github.com/gfm/).
|
|
28
|
+
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
//# Dependencies
|
|
32
|
+
//## Internal
|
|
33
|
+
import { deepStrictEqual } from './cno-assert.js';
|
|
34
|
+
import TestNS from './cno-test-matrix.js';
|
|
35
|
+
import DefaultExport from './cno-bytes.js';
|
|
36
|
+
import * as NamespaceExport from './cno-bytes.js';
|
|
37
|
+
import { getBase16FromBuffer, getBufferFromBase16, deriveAOBStringFromSamplesArray, AOB } from './cno-bytes.js';
|
|
38
|
+
//## Standard
|
|
39
|
+
//## External
|
|
40
|
+
|
|
41
|
+
//# Constants
|
|
42
|
+
const FILENAME = 'cno-bytes.test.js';
|
|
43
|
+
//## Errors
|
|
44
|
+
|
|
45
|
+
//# Global Variables
|
|
46
|
+
/**## Functions*/
|
|
47
|
+
TestNS.test( 'getBase16FromBuffer', async function( t ){
|
|
48
|
+
var tm = new TestNS.TestMatrix( { testContext: t } );
|
|
49
|
+
tm.addFunction( { name: 'defaultExport', func: DefaultExport.getBase16FromBuffer } );
|
|
50
|
+
tm.addFunction( { name: 'namespaceExport', func: NamespaceExport.getBase16FromBuffer } );
|
|
51
|
+
tm.addFunction( { name: 'namedExport', func: getBase16FromBuffer } );
|
|
52
|
+
tm.addCondition( {
|
|
53
|
+
name: 'input_buffer_type',
|
|
54
|
+
success: false,
|
|
55
|
+
promise: false,
|
|
56
|
+
args: [ null ],
|
|
57
|
+
expected: { constructor: TypeError, code: 'ERR_INVALID_ARG_TYPE' }
|
|
58
|
+
} );
|
|
59
|
+
tm.addCondition( {
|
|
60
|
+
name: 'input_options_type',
|
|
61
|
+
success: false,
|
|
62
|
+
promise: false,
|
|
63
|
+
args: [ Buffer.from( 'text', 'utf8' ), false ],
|
|
64
|
+
expected: { constructor: TypeError, code: 'ERR_INVALID_ARG_TYPE' }
|
|
65
|
+
} );
|
|
66
|
+
tm.addCondition( {
|
|
67
|
+
name: 'noop',
|
|
68
|
+
success: true,
|
|
69
|
+
debug: true,
|
|
70
|
+
promise: false,
|
|
71
|
+
args: [ Buffer.from( 'text', 'utf8' ), { noop: true } ],
|
|
72
|
+
expected: ''
|
|
73
|
+
} );
|
|
74
|
+
tm.addCondition( {
|
|
75
|
+
name: 'defaults',
|
|
76
|
+
success: true,
|
|
77
|
+
promise: false,
|
|
78
|
+
args: [ Buffer.from( 'text\n\0\t ~', 'utf8' ) ],
|
|
79
|
+
expected: '746578740A0009207E'
|
|
80
|
+
} );
|
|
81
|
+
tm.addCondition( {
|
|
82
|
+
name: 'lowercase',
|
|
83
|
+
success: true,
|
|
84
|
+
promise: false,
|
|
85
|
+
args: [ Buffer.from( 'text\n\0\t ~', 'utf8' ), { uppercase: false } ],
|
|
86
|
+
expected: '746578740a0009207e'
|
|
87
|
+
} );
|
|
88
|
+
tm.addCondition( {
|
|
89
|
+
name: 'space',
|
|
90
|
+
success: true,
|
|
91
|
+
promise: false,
|
|
92
|
+
args: [ Buffer.from( 'text\n\0\t ~', 'utf8' ), { space: true } ],
|
|
93
|
+
expected: '74 65 78 74 0A 00 09 20 7E'
|
|
94
|
+
} );
|
|
95
|
+
tm.addCondition( {
|
|
96
|
+
name: 'prefix',
|
|
97
|
+
success: true,
|
|
98
|
+
promise: false,
|
|
99
|
+
args: [ Buffer.from( 'text\n\0\t ~', 'utf8' ), { prefix: true } ],
|
|
100
|
+
expected: 'F746578740A0009207E'
|
|
101
|
+
} );
|
|
102
|
+
tm.addCondition( {
|
|
103
|
+
name: 'lower-prefix',
|
|
104
|
+
success: true,
|
|
105
|
+
promise: false,
|
|
106
|
+
args: [ Buffer.from( 'text\n\0\t ~', 'utf8' ), { uppercase: false, prefix: true } ],
|
|
107
|
+
expected: 'f746578740a0009207e'
|
|
108
|
+
} );
|
|
109
|
+
tm.addCondition( {
|
|
110
|
+
name: 'all-toggled',
|
|
111
|
+
success: true,
|
|
112
|
+
promise: false,
|
|
113
|
+
args: [ Buffer.from( 'text\n\0\t ~', 'utf8' ), { uppercase: false, space: true, prefix: true } ],
|
|
114
|
+
expected: 'f74 65 78 74 0a 00 09 20 7e'
|
|
115
|
+
} );
|
|
116
|
+
await tm.run( { logFunction: console.log } );
|
|
117
|
+
} );
|
|
118
|
+
TestNS.test( 'getBufferFromBase16', async function( t ){
|
|
119
|
+
var tm = new TestNS.TestMatrix( { testContext: t } );
|
|
120
|
+
tm.addFunction( { name: 'defaultExport', func: DefaultExport.getBufferFromBase16 } );
|
|
121
|
+
tm.addFunction( { name: 'namespaceExport', func: NamespaceExport.getBufferFromBase16 } );
|
|
122
|
+
tm.addFunction( { name: 'namedExport', func: getBufferFromBase16 } );
|
|
123
|
+
tm.addCondition( {
|
|
124
|
+
name: 'input_string_type',
|
|
125
|
+
success: false,
|
|
126
|
+
promise: false,
|
|
127
|
+
args: [ false ],
|
|
128
|
+
expected: { constructor: TypeError, code: 'ERR_INVALID_ARG_TYPE' }
|
|
129
|
+
} );
|
|
130
|
+
tm.addCondition( {
|
|
131
|
+
name: 'input_string_value',
|
|
132
|
+
success: false,
|
|
133
|
+
promise: false,
|
|
134
|
+
args: [ '' ],
|
|
135
|
+
expected: { constructor: Error, code: 'ERR_INVALID_ARG_VALUE' }
|
|
136
|
+
} );
|
|
137
|
+
tm.addCondition( {
|
|
138
|
+
name: 'input_options_type',
|
|
139
|
+
success: false,
|
|
140
|
+
promise: false,
|
|
141
|
+
args: [ '746578740A0009207E', false ],
|
|
142
|
+
expected: { constructor: TypeError, code: 'ERR_INVALID_ARG_TYPE' }
|
|
143
|
+
} );
|
|
144
|
+
tm.addCondition( {
|
|
145
|
+
name: 'noop',
|
|
146
|
+
success: true,
|
|
147
|
+
promise: false,
|
|
148
|
+
args: [ '746578740A0009207E', { noop: true } ],
|
|
149
|
+
expected: null
|
|
150
|
+
} );
|
|
151
|
+
tm.addCondition( {
|
|
152
|
+
name: 'defaults',
|
|
153
|
+
success: true,
|
|
154
|
+
promise: false,
|
|
155
|
+
args: [ '746578740A0009207E' ],
|
|
156
|
+
expected: Buffer.from( 'text\n\0\t ~', 'utf8' )
|
|
157
|
+
} );
|
|
158
|
+
tm.addCondition( {
|
|
159
|
+
name: 'lowercase',
|
|
160
|
+
success: true,
|
|
161
|
+
promise: false,
|
|
162
|
+
args: [ '746578740a0009207e' ],
|
|
163
|
+
expected: Buffer.from( 'text\n\0\t ~', 'utf8' )
|
|
164
|
+
} );
|
|
165
|
+
tm.addCondition( {
|
|
166
|
+
name: 'space',
|
|
167
|
+
success: true,
|
|
168
|
+
promise: false,
|
|
169
|
+
args: [ '74 65 78 74 0A 00 09 20 7E', { space: true } ],
|
|
170
|
+
expected: Buffer.from( 'text\n\0\t ~', 'utf8' )
|
|
171
|
+
} );
|
|
172
|
+
tm.addCondition( {
|
|
173
|
+
name: 'prefix',
|
|
174
|
+
success: true,
|
|
175
|
+
promise: false,
|
|
176
|
+
args: [ 'F746578740A0009207E', { prefix: true } ],
|
|
177
|
+
expected: Buffer.from( 'text\n\0\t ~', 'utf8' )
|
|
178
|
+
} );
|
|
179
|
+
tm.addCondition( {
|
|
180
|
+
name: 'lower-prefix',
|
|
181
|
+
success: true,
|
|
182
|
+
promise: false,
|
|
183
|
+
args: [ 'f746578740a0009207e', { prefix: true } ],
|
|
184
|
+
expected: Buffer.from( 'text\n\0\t ~', 'utf8' )
|
|
185
|
+
} );
|
|
186
|
+
tm.addCondition( {
|
|
187
|
+
name: 'all-toggled',
|
|
188
|
+
success: true,
|
|
189
|
+
promise: false,
|
|
190
|
+
args: [ 'f74 65 78 74 0a 00 09 20 7e', { space: true, prefix: true } ],
|
|
191
|
+
expected: Buffer.from( 'text\n\0\t ~', 'utf8' )
|
|
192
|
+
} );
|
|
193
|
+
await tm.run();
|
|
194
|
+
} );
|
|
195
|
+
TestNS.test( 'deriveAOBStringFromSamplesArray', async function( t ){
|
|
196
|
+
var tm = new TestNS.TestMatrix( { testContext: t } );
|
|
197
|
+
tm.addFunction( { name: 'defaultExport', func: DefaultExport.deriveAOBStringFromSamplesArray } );
|
|
198
|
+
tm.addFunction( { name: 'namespaceExport', func: NamespaceExport.deriveAOBStringFromSamplesArray } );
|
|
199
|
+
tm.addFunction( { name: 'namedExport', func: deriveAOBStringFromSamplesArray } );
|
|
200
|
+
tm.addCondition( { name: 'invalid-null', success: false, args: [ null ], expected: { constructor: TypeError, code: 'ERR_INVALID_ARG_TYPE' } } );
|
|
201
|
+
tm.addCondition( { name: 'invalid-nonarray', success: false, args: [ 'AABB' ], expected: { constructor: TypeError, code: 'ERR_INVALID_ARG_TYPE' } } );
|
|
202
|
+
tm.addCondition( { name: 'single-sample', success: true, args: [ [ 'AABB' ] ], expected: 'AABB' } );
|
|
203
|
+
tm.addCondition( { name: 'identical-samples', success: true, args: [ [ 'ABCD', 'ABCD', 'ABCD' ] ], expected: 'ABCD' } );
|
|
204
|
+
tm.addCondition( { name: 'differing-samples', success: true, args: [ [ 'AABB', 'ABBB' ] ], expected: 'AxBB' } );
|
|
205
|
+
tm.addCondition( { name: 'all-differ', success: true, args: [ [ 'AAAA', 'BBBB' ] ], expected: 'xxxx' } );
|
|
206
|
+
await tm.run();
|
|
207
|
+
} );
|
|
208
|
+
TestNS.test( 'AOB', async function( t ){
|
|
209
|
+
// Callable with and without `new`.
|
|
210
|
+
var aob = AOB( {} );
|
|
211
|
+
deepStrictEqual( aob instanceof AOB, true );
|
|
212
|
+
deepStrictEqual( new AOB( {} ).name, '' );
|
|
213
|
+
deepStrictEqual( aob.string, '' );
|
|
214
|
+
deepStrictEqual( aob.inputLength, 0 );
|
|
215
|
+
deepStrictEqual( aob.outputLength, 0 );
|
|
216
|
+
deepStrictEqual( aob.samplesArray, [] );
|
|
217
|
+
deepStrictEqual( DefaultExport.AOB( {} ) instanceof AOB, true );
|
|
218
|
+
deepStrictEqual( NamespaceExport.AOB( {} ) instanceof AOB, true );
|
|
219
|
+
} );
|
|
220
|
+
|
|
221
|
+
// cno-bytes.test.js EOF
|
|
222
|
+
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
# [cno-constants.js](src/cno-constants.js)
|
|
4
|
+
> Standard numeric and mathematical constants.
|
|
5
|
+
|
|
6
|
+
Author: Anadian
|
|
7
|
+
|
|
8
|
+
Code license: MIT
|
|
9
|
+
```
|
|
10
|
+
Copyright 2025 Anadian
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
12
|
+
software and associated documentation files (the "Software"), to deal in the Software
|
|
13
|
+
without restriction, including without limitation the rights to use, copy, modify,
|
|
14
|
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
15
|
+
permit persons to whom the Software is furnished to do so, subject to the following
|
|
16
|
+
conditions:
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all copies
|
|
18
|
+
or substantial portions of the Software.
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
20
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
21
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
22
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
23
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
24
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
```
|
|
26
|
+
Documentation License: [](http://creativecommons.org/licenses/by-sa/4.0/)
|
|
27
|
+
> The source-code comments and documentation are written in [GitHub Flavored Markdown](https://github.github.com/gfm/).
|
|
28
|
+
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
//# Dependencies
|
|
32
|
+
//## Internal
|
|
33
|
+
//## Standard
|
|
34
|
+
//## External
|
|
35
|
+
import * as MathJS from 'mathjs';
|
|
36
|
+
//# Constants
|
|
37
|
+
const FILENAME = 'cno-constants.js';
|
|
38
|
+
|
|
39
|
+
export const PI = 3.14159265358979323;
|
|
40
|
+
export const HALF_PI = PI / 2;
|
|
41
|
+
export const QUARTER_PI = PI / 4;
|
|
42
|
+
export const TAU = MathJS.tau || ( 2 * PI );
|
|
43
|
+
export const E = MathJS.E || 2.718281828459045;
|
|
44
|
+
export const PHI = MathJS.phi || 1.618033988749895;
|
|
45
|
+
export const I = MathJS.i;
|
|
46
|
+
export const SQRT2 = Math.sqrt( 2 );
|
|
47
|
+
export const SQRT3 = Math.sqrt( 3 );
|
|
48
|
+
export const SQRT1_2 = SQRT2 / 2;
|
|
49
|
+
export const SQRT1_3 = SQRT3 / 3;
|
|
50
|
+
export const DEG_TO_RAD = ( PI / 180.0 );
|
|
51
|
+
export const RAD_TO_DEG = ( 180.0 / PI );
|
|
52
|
+
export const C = 299792458;
|
|
53
|
+
|
|
54
|
+
const NAMESPACE = {};
|
|
55
|
+
Object.defineProperties( NAMESPACE, {
|
|
56
|
+
PI: {
|
|
57
|
+
value: PI,
|
|
58
|
+
enumerable: true
|
|
59
|
+
},
|
|
60
|
+
HALF_PI: {
|
|
61
|
+
value: HALF_PI,
|
|
62
|
+
enumerable: true
|
|
63
|
+
},
|
|
64
|
+
QUARTER_PI: {
|
|
65
|
+
value: QUARTER_PI,
|
|
66
|
+
enumerable: true
|
|
67
|
+
},
|
|
68
|
+
TAU: {
|
|
69
|
+
value: TAU,
|
|
70
|
+
enumerable: true
|
|
71
|
+
},
|
|
72
|
+
E: {
|
|
73
|
+
value: E,
|
|
74
|
+
enumerable: true
|
|
75
|
+
},
|
|
76
|
+
PHI: {
|
|
77
|
+
value: PHI,
|
|
78
|
+
enumerable: true
|
|
79
|
+
},
|
|
80
|
+
I: {
|
|
81
|
+
value: I,
|
|
82
|
+
enumerable: true
|
|
83
|
+
},
|
|
84
|
+
SQRT2: {
|
|
85
|
+
value: SQRT2,
|
|
86
|
+
enumerable: true
|
|
87
|
+
},
|
|
88
|
+
SQRT3: {
|
|
89
|
+
value: SQRT3,
|
|
90
|
+
enumerable: true
|
|
91
|
+
},
|
|
92
|
+
SQRT1_2: {
|
|
93
|
+
value: SQRT1_2,
|
|
94
|
+
enumerable: true
|
|
95
|
+
},
|
|
96
|
+
SQRT1_3: {
|
|
97
|
+
value: SQRT1_3,
|
|
98
|
+
enumerable: true
|
|
99
|
+
},
|
|
100
|
+
DEG_TO_RAD: {
|
|
101
|
+
value: DEG_TO_RAD,
|
|
102
|
+
enumerable: true
|
|
103
|
+
},
|
|
104
|
+
RAD_TO_DEG: {
|
|
105
|
+
value: RAD_TO_DEG,
|
|
106
|
+
enumerable: true
|
|
107
|
+
},
|
|
108
|
+
C: {
|
|
109
|
+
value: C,
|
|
110
|
+
enumerable: true
|
|
111
|
+
}
|
|
112
|
+
} );
|
|
113
|
+
//## Errors
|
|
114
|
+
|
|
115
|
+
//# Global Variables
|
|
116
|
+
/**## Functions*/
|
|
117
|
+
|
|
118
|
+
export { NAMESPACE as default };
|
|
119
|
+
|
|
120
|
+
// cno-constants.js EOF
|
|
121
|
+
|