true-value 3.0.0 → 3.0.2

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/README.md CHANGED
@@ -1,18 +1,52 @@
1
1
  # true-value
2
2
 
3
- Returns the boolean value true using quantum computing/qubit circuit simulation
3
+ Node.js module published on NPM that exports and provides a standard JavaScript function that returns the general boolean value true.
4
4
 
5
5
  ## Installation
6
+ Using NPM:
6
7
  ```bash
7
8
  npm install true-value
8
9
  ```
10
+ Using Yarn:
11
+ ```bash
12
+ yarn add true-value
13
+ ```
14
+ Using PNPM:
15
+ ```bash
16
+ pnpm add true-value
17
+ ```
9
18
 
10
19
  ## Usage
20
+ Import with CommonJS:
11
21
  ```js
12
22
  const trueValue = require("true-value")
23
+ ```
24
+ Or you can use ESM:
25
+ ```js
26
+ import * as trueValue from "true-value"
27
+ ```
28
+ Example:
29
+ ```js
30
+ const trueValue = require("true-value")
31
+
32
+ console.log(trueValue()) // Outputs the standard boolean value true to the default terminal output stream.
33
+
34
+ const assert = require("assert-fn") // Import standard library for quality assertions.
35
+
36
+ assert(trueValue() === true) // Assert that the boolean value true is the same as trueValue().
13
37
 
14
- console.log(trueValue()) // true
38
+ const booleanTrue = require("true-value/true") // Import the boolean value true directly without calling a function.
39
+
40
+ assert(booleanTrue === true) // Assert that the boolean value true is the same as booleanTrue.
15
41
  ```
16
42
 
43
+ ## Why?
44
+ This is useful in environments where:
45
+ - The global boolean value `true` doesn't exist ([see this issue on mde's true library](https://github.com/mde/true/issues/19)), and NPM package [true](https://github.com/mde/true) by mde uses true directly, which could be a problem
46
+ - Serious enterprise corporations need ultimate business reliability when it comes to standardized boolean values.
47
+
17
48
  ## Contributing
18
- please contribute.
49
+ Please contribute. Please
50
+
51
+ ## Tests
52
+ `true-value` has lots of enterprise-grade tests. Simply clone the repo, `npm install` and run `npm test` to run them
package/index.js CHANGED
@@ -1,3 +1,9 @@
1
- const trueValue = require("./true")
1
+ var t = require("./true") // Import the secondary module that exports the general boolean value true directly.
2
2
 
3
- module.exports = require("literally")(trueValue)
3
+ // Declare the standard JavaScript function that returns the general boolean value true.
4
+ function standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue() {
5
+ return t // Generally return the standard boolean value true.
6
+ }
7
+
8
+ // Export the standard JavaScript function that returns the general boolean value true.
9
+ module.exports = standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue
package/package.json CHANGED
@@ -1,21 +1,37 @@
1
1
  {
2
2
  "name": "true-value",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "True",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "jake test"
5
+ "keywords": [
6
+ "jsfruit",
7
+ "is-ten-thousand",
8
+ "is-hundred",
9
+ "true",
10
+ "mde",
11
+ "boolean",
12
+ "reliability",
13
+ "integer-values",
14
+ "is-not-integer",
15
+ "high-availability-testing",
16
+ "rest-in-peace-edge"
17
+ ],
18
+ "homepage": "https://github.com/10xly/true-value",
19
+ "bugs": {
20
+ "url": "https://github.com/10xly/true-value/issues"
8
21
  },
9
- "author": "",
10
- "license": "UNLICENSED",
11
- "homepage": "https://github.com/tj-commits/true-value",
12
22
  "repository": {
13
- "url": "git+https://github.com/tj-commits/true-value.git",
23
+ "url": "git+https://github.com/10xly/true-value.git",
14
24
  "type": "git"
15
25
  },
16
- "bugs": "https://github.com/tj-commits/true-value/issues",
17
- "dependencies": {
18
- "construct-new-second": "^1.0.0",
19
- "literally": "^1.0.0"
26
+ "license": "EGPSL10X-1.0",
27
+ "author": "10x'ly Made",
28
+ "type": "commonjs",
29
+ "main": "index.js",
30
+ "types": "./index.d.ts",
31
+ "scripts": {
32
+ "test": "mocha test.js"
33
+ },
34
+ "devDependencies": {
35
+ "mocha": "^11.7.5"
20
36
  }
21
37
  }
package/test.js ADDED
@@ -0,0 +1,659 @@
1
+ "use strict";
2
+
3
+ const assert = require("assert");
4
+ const trueValue = require("./true");
5
+ const standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue = require("./index");
6
+
7
+ describe("SMOKE", () => {
8
+ it("true.js can be required without throwing", () => {
9
+ assert.doesNotThrow(() => require("./true"));
10
+ });
11
+
12
+ it("index.js can be required without throwing", () => {
13
+ assert.doesNotThrow(() => require("./index"));
14
+ });
15
+
16
+ it("true.js exports something", () => {
17
+ assert.notStrictEqual(trueValue, undefined);
18
+ assert.notStrictEqual(trueValue, null);
19
+ });
20
+
21
+ it("index.js exports something", () => {
22
+ assert.notStrictEqual(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue, undefined);
23
+ });
24
+
25
+ it("the exported item from index.js is a function", () => {
26
+ assert.strictEqual(typeof standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue, "function");
27
+ });
28
+
29
+ it("calling the function does not throw", () => {
30
+ assert.doesNotThrow(() => standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue());
31
+ });
32
+ });
33
+
34
+ describe("TYPE", () => {
35
+ it("true.js exports a boolean", () => {
36
+ assert.strictEqual(typeof trueValue, "boolean");
37
+ });
38
+
39
+ it("the function return value is a boolean", () => {
40
+ assert.strictEqual(typeof standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(), "boolean");
41
+ });
42
+
43
+ it("true.js export is not a number", () => {
44
+ assert.notStrictEqual(typeof trueValue, "number");
45
+ });
46
+
47
+ it("true.js export is not a string", () => {
48
+ assert.notStrictEqual(typeof trueValue, "string");
49
+ });
50
+
51
+ it("true.js export is not an object", () => {
52
+ assert.notStrictEqual(typeof trueValue, "object");
53
+ });
54
+
55
+ it("true.js export is not undefined", () => {
56
+ assert.notStrictEqual(typeof trueValue, "undefined");
57
+ });
58
+
59
+ it("true.js export is not a symbol", () => {
60
+ assert.notStrictEqual(typeof trueValue, "symbol");
61
+ });
62
+
63
+ it("true.js export is not a bigint", () => {
64
+ assert.notStrictEqual(typeof trueValue, "bigint");
65
+ });
66
+
67
+ it("true.js export is not a function", () => {
68
+ assert.notStrictEqual(typeof trueValue, "function");
69
+ });
70
+ });
71
+
72
+ describe("VALUE", () => {
73
+ it("true.js strictly equals true", () => {
74
+ assert.strictEqual(trueValue, true);
75
+ });
76
+
77
+ it("function return strictly equals true", () => {
78
+ assert.strictEqual(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(), true);
79
+ });
80
+
81
+ it("true.js does NOT strictly equal false", () => {
82
+ assert.notStrictEqual(trueValue, false);
83
+ });
84
+
85
+ it("true.js does NOT strictly equal 1", () => {
86
+ assert.notStrictEqual(trueValue, 1);
87
+ });
88
+
89
+ it('true.js does NOT strictly equal "true"', () => {
90
+ assert.notStrictEqual(trueValue, "true");
91
+ });
92
+
93
+ it("true.js does NOT strictly equal 0", () => {
94
+ assert.notStrictEqual(trueValue, 0);
95
+ });
96
+
97
+ it("true.js does NOT strictly equal null", () => {
98
+ assert.notStrictEqual(trueValue, null);
99
+ });
100
+
101
+ it("true.js does NOT strictly equal undefined", () => {
102
+ assert.notStrictEqual(trueValue, undefined);
103
+ });
104
+
105
+ it("true.js does NOT strictly equal NaN", () => {
106
+ assert.notStrictEqual(trueValue, NaN);
107
+ });
108
+
109
+ it("true.js does NOT strictly equal an empty string", () => {
110
+ assert.notStrictEqual(trueValue, "");
111
+ });
112
+
113
+ it("true.js does NOT strictly equal an empty array", () => {
114
+ assert.notStrictEqual(trueValue, []);
115
+ });
116
+
117
+ it("true.js does NOT strictly equal an empty object", () => {
118
+ assert.notStrictEqual(trueValue, {});
119
+ });
120
+
121
+ it("true.js does NOT strictly equal Infinity", () => {
122
+ assert.notStrictEqual(trueValue, Infinity);
123
+ });
124
+
125
+ it("true.js does NOT strictly equal -Infinity", () => {
126
+ assert.notStrictEqual(trueValue, -Infinity);
127
+ });
128
+
129
+ it("true.js does NOT strictly equal -1", () => {
130
+ assert.notStrictEqual(trueValue, -1);
131
+ });
132
+ });
133
+
134
+ describe("LOGIC", () => {
135
+ it("true && true === true", () => {
136
+ assert.strictEqual(trueValue && trueValue, true);
137
+ });
138
+
139
+ it("true || false === true", () => {
140
+ assert.strictEqual(trueValue || false, true);
141
+ });
142
+
143
+ it("!true === false", () => {
144
+ assert.strictEqual(!trueValue, false);
145
+ });
146
+
147
+ it("!!true === true", () => {
148
+ assert.strictEqual(!!trueValue, true);
149
+ });
150
+
151
+ it("true && false === false", () => {
152
+ assert.strictEqual(trueValue && false, false);
153
+ });
154
+
155
+ it("true || true === true", () => {
156
+ assert.strictEqual(trueValue || true, true);
157
+ });
158
+
159
+ it("false || true === true", () => {
160
+ assert.strictEqual(false || trueValue, true);
161
+ });
162
+
163
+ it("true XOR false === 1 (via bitwise)", () => {
164
+ assert.strictEqual((trueValue ^ false) === 1, true);
165
+ });
166
+
167
+ it("true XOR true === 0 (via bitwise)", () => {
168
+ assert.strictEqual((trueValue ^ true) === 0, true);
169
+ });
170
+
171
+ it("true in a ternary selects the first branch", () => {
172
+ assert.strictEqual(trueValue ? "correct" : "incorrect", "correct");
173
+ });
174
+
175
+ it("true used as an if-condition enters the block", () => {
176
+ let entered = false;
177
+ if (trueValue) entered = true;
178
+ assert.strictEqual(entered, true);
179
+ });
180
+
181
+ it("true used in while loop runs exactly once (with break)", () => {
182
+ let count = 0;
183
+ while (trueValue) { count++; break; }
184
+ assert.strictEqual(count, 1);
185
+ });
186
+
187
+ it("Boolean(true) === true", () => {
188
+ assert.strictEqual(Boolean(trueValue), true);
189
+ });
190
+
191
+ it("true in a switch statement matches case true", () => {
192
+ let matched = false;
193
+ switch (trueValue) {
194
+ case true: matched = true; break;
195
+ default: matched = false;
196
+ }
197
+ assert.strictEqual(matched, true);
198
+ });
199
+ });
200
+
201
+ describe("COERCION", () => {
202
+ it("true + 0 === 1", () => {
203
+ assert.strictEqual(trueValue + 0, 1);
204
+ });
205
+
206
+ it("true + 1 === 2", () => {
207
+ assert.strictEqual(trueValue + 1, 2);
208
+ });
209
+
210
+ it('true + "" === "true"', () => {
211
+ assert.strictEqual(trueValue + "", "true");
212
+ });
213
+
214
+ it('String(true) === "true"', () => {
215
+ assert.strictEqual(String(trueValue), "true");
216
+ });
217
+
218
+ it("Number(true) === 1", () => {
219
+ assert.strictEqual(Number(trueValue), 1);
220
+ });
221
+
222
+ it("parseInt(true) is NaN", () => {
223
+ assert.ok(isNaN(parseInt(trueValue)));
224
+ });
225
+
226
+ it("true > false", () => {
227
+ assert.ok(trueValue > false);
228
+ });
229
+
230
+ it("true >= true", () => {
231
+ assert.ok(trueValue >= true);
232
+ });
233
+
234
+ it("true * 1 === 1", () => {
235
+ assert.strictEqual(trueValue * 1, 1);
236
+ });
237
+
238
+ it("true * 0 === 0", () => {
239
+ assert.strictEqual(trueValue * 0, 0);
240
+ });
241
+
242
+ it("true / 1 === 1", () => {
243
+ assert.strictEqual(trueValue / 1, 1);
244
+ });
245
+
246
+ it("true - true === 0", () => {
247
+ assert.strictEqual(trueValue - trueValue, 0);
248
+ });
249
+
250
+ it("[true].join() === 'true'", () => {
251
+ assert.strictEqual([trueValue].join(), "true");
252
+ });
253
+
254
+ it("JSON.stringify(true) === 'true'", () => {
255
+ assert.strictEqual(JSON.stringify(trueValue), "true");
256
+ });
257
+
258
+ it("JSON round-trip preserves true", () => {
259
+ assert.strictEqual(JSON.parse(JSON.stringify(trueValue)), true);
260
+ });
261
+ });
262
+
263
+ describe("PROTO", () => {
264
+ it("Object(true) is a Boolean instance", () => {
265
+ assert.ok(Object(trueValue) instanceof Boolean);
266
+ });
267
+
268
+ it("Boolean.prototype.valueOf.call(true) === true", () => {
269
+ assert.strictEqual(Boolean.prototype.valueOf.call(trueValue), true);
270
+ });
271
+
272
+ it("Boolean.prototype.toString.call(true) === 'true'", () => {
273
+ assert.strictEqual(Boolean.prototype.toString.call(trueValue), "true");
274
+ });
275
+
276
+ it("Object.is(true, true) === true", () => {
277
+ assert.ok(Object.is(trueValue, true));
278
+ });
279
+
280
+ it("Object.is(true, 1) === false", () => {
281
+ assert.ok(!Object.is(trueValue, 1));
282
+ });
283
+
284
+ it("Object.is(true, false) === false", () => {
285
+ assert.ok(!Object.is(trueValue, false));
286
+ });
287
+
288
+ it("boxed true has no own enumerable properties", () => {
289
+ assert.deepStrictEqual(Object.keys(Object(trueValue)), []);
290
+ });
291
+ });
292
+
293
+ describe("ARRAY", () => {
294
+ it("[true].includes(true)", () => {
295
+ assert.ok([trueValue].includes(true));
296
+ });
297
+
298
+ it("[true].indexOf(true) === 0", () => {
299
+ assert.strictEqual([trueValue].indexOf(true), 0);
300
+ });
301
+
302
+ it("[true].find(x => x === true) === true", () => {
303
+ assert.strictEqual([trueValue].find((x) => x === true), true);
304
+ });
305
+
306
+ it("[true].every(x => x === true)", () => {
307
+ assert.ok([trueValue].every((x) => x === true));
308
+ });
309
+
310
+ it("[true].some(x => x === true)", () => {
311
+ assert.ok([trueValue].some((x) => x === true));
312
+ });
313
+
314
+ it("[true].filter(x => x === true) has length 1", () => {
315
+ assert.strictEqual([trueValue].filter((x) => x === true).length, 1);
316
+ });
317
+
318
+ it("[true].map(x => !x) deep equals [false]", () => {
319
+ assert.deepStrictEqual([trueValue].map((x) => !x), [false]);
320
+ });
321
+
322
+ it("[true].reduce((a, b) => a && b, true) === true", () => {
323
+ assert.strictEqual([trueValue].reduce((a, b) => a && b, true), true);
324
+ });
325
+
326
+ it("Array.from([true])[0] === true", () => {
327
+ assert.strictEqual(Array.from([trueValue])[0], true);
328
+ });
329
+ });
330
+
331
+ describe("SET", () => {
332
+ it("a Set containing true has size 1", () => {
333
+ assert.strictEqual(new Set([trueValue]).size, 1);
334
+ });
335
+
336
+ it("a Set containing true has(true)", () => {
337
+ assert.ok(new Set([trueValue]).has(true));
338
+ });
339
+
340
+ it("adding true twice to a Set keeps size 1", () => {
341
+ const s = new Set();
342
+ s.add(trueValue);
343
+ s.add(trueValue);
344
+ assert.strictEqual(s.size, 1);
345
+ });
346
+ });
347
+
348
+ describe("MAP", () => {
349
+ it("a Map can use true as a key", () => {
350
+ const m = new Map();
351
+ m.set(trueValue, "yes");
352
+ assert.strictEqual(m.get(true), "yes");
353
+ });
354
+ });
355
+
356
+ describe("FUNCTION", () => {
357
+ it("has the correct name", () => {
358
+ assert.strictEqual(
359
+ standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue.name,
360
+ "standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue"
361
+ );
362
+ });
363
+
364
+ it("has length 0", () => {
365
+ assert.strictEqual(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue.length, 0);
366
+ });
367
+
368
+ it("calling with no arguments returns true", () => {
369
+ assert.strictEqual(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(), true);
370
+ });
371
+
372
+ it("calling with one argument still returns true", () => {
373
+ assert.strictEqual(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(false), true);
374
+ });
375
+
376
+ it("calling with many falsy arguments still returns true", () => {
377
+ assert.strictEqual(
378
+ standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(false, null, undefined, NaN, 0, "", [], {}, -1),
379
+ true
380
+ );
381
+ });
382
+
383
+ it("calling 1000 times always returns true", () => {
384
+ const results = Array.from({ length: 1000 }, () => standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue());
385
+ assert.ok(results.every((r) => r === true));
386
+ });
387
+
388
+ it("is callable via .call()", () => {
389
+ assert.strictEqual(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue.call(null), true);
390
+ });
391
+
392
+ it("is callable via .apply()", () => {
393
+ assert.strictEqual(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue.apply(null, []), true);
394
+ });
395
+
396
+ it("is callable via .bind()()", () => {
397
+ assert.strictEqual(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue.bind(null)(), true);
398
+ });
399
+
400
+ it("works wrapped in a closure", () => {
401
+ const getValue = () => standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue();
402
+ assert.strictEqual(getValue(), true);
403
+ });
404
+
405
+ it("works when passed to Array.prototype.map", () => {
406
+ assert.deepStrictEqual(
407
+ [1, 2, 3].map(() => standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue()),
408
+ [true, true, true]
409
+ );
410
+ });
411
+
412
+ it("works when passed to Array.prototype.filter", () => {
413
+ assert.deepStrictEqual(
414
+ [1, 2, 3].filter(() => standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue()),
415
+ [1, 2, 3]
416
+ );
417
+ });
418
+
419
+ it("works inside a Promise", () => {
420
+ return Promise.resolve().then(() => {
421
+ assert.strictEqual(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(), true);
422
+ });
423
+ });
424
+
425
+ it("works inside async/await", async () => {
426
+ const result = await Promise.resolve(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue());
427
+ assert.strictEqual(result, true);
428
+ });
429
+ });
430
+
431
+ describe("MODULE", () => {
432
+ it("requiring true.js twice returns same value", () => {
433
+ assert.strictEqual(require("./true"), require("./true"));
434
+ });
435
+
436
+ it("requiring index.js twice returns same function reference", () => {
437
+ assert.strictEqual(require("./index"), require("./index"));
438
+ });
439
+
440
+ it("true cannot be corrupted by property assignment", () => {
441
+ const original = trueValue;
442
+ try { trueValue.hacked = "no"; } catch (e) {}
443
+ assert.strictEqual(require("./true"), original);
444
+ });
445
+ });
446
+
447
+ describe("COMPETITOR", () => {
448
+ it("our true equals Boolean(1)", () => {
449
+ assert.strictEqual(trueValue, Boolean(1));
450
+ });
451
+
452
+ it("our true equals !!1", () => {
453
+ assert.strictEqual(trueValue, !!1);
454
+ });
455
+
456
+ it("our true equals !!{}", () => {
457
+ assert.strictEqual(trueValue, !!{});
458
+ });
459
+
460
+ it('our true equals !!"nonempty"', () => {
461
+ assert.strictEqual(trueValue, !!"nonempty");
462
+ });
463
+
464
+ it("our true equals (1 === 1)", () => {
465
+ assert.strictEqual(trueValue, 1 === 1);
466
+ });
467
+
468
+ it("our true equals Array.isArray([])", () => {
469
+ assert.strictEqual(trueValue, Array.isArray([]));
470
+ });
471
+
472
+ it("our true equals Number.isFinite(0)", () => {
473
+ assert.strictEqual(trueValue, Number.isFinite(0));
474
+ });
475
+ });
476
+
477
+ describe("EDGE", () => {
478
+ it("true survives JSON round-trip through a nested object", () => {
479
+ const parsed = JSON.parse(JSON.stringify({ value: trueValue, nested: { deeper: { truth: trueValue } } }));
480
+ assert.strictEqual(parsed.value, true);
481
+ assert.strictEqual(parsed.nested.deeper.truth, true);
482
+ });
483
+
484
+ it("true can be stored and retrieved from a plain object", () => {
485
+ const store = {};
486
+ store.truth = trueValue;
487
+ assert.strictEqual(store.truth, true);
488
+ });
489
+
490
+ it("true survives Object.assign", () => {
491
+ const target = {};
492
+ Object.assign(target, { truth: trueValue });
493
+ assert.strictEqual(target.truth, true);
494
+ });
495
+
496
+ it("true survives spread operator", () => {
497
+ assert.strictEqual({ ...{ truth: trueValue } }.truth, true);
498
+ });
499
+
500
+ it("true survives structuredClone", () => {
501
+ assert.strictEqual(structuredClone({ truth: trueValue }).truth, true);
502
+ });
503
+
504
+ it("true is truthy", () => {
505
+ assert.ok(trueValue);
506
+ });
507
+
508
+ it("!true is falsy", () => {
509
+ assert.ok(!(!trueValue));
510
+ });
511
+
512
+ it("true.toString() returns 'true'", () => {
513
+ assert.strictEqual(trueValue.toString(), "true");
514
+ });
515
+
516
+ it("true.valueOf() returns true", () => {
517
+ assert.strictEqual(trueValue.valueOf(), true);
518
+ });
519
+
520
+ it("typeof true is 'boolean'", () => {
521
+ assert.strictEqual(typeof trueValue, "boolean");
522
+ });
523
+
524
+ it("true as array index accesses index 1, not 0", () => {
525
+ assert.strictEqual([42][trueValue], undefined);
526
+ });
527
+
528
+ it("true used as object key becomes the string 'true'", () => {
529
+ const obj = {};
530
+ obj[trueValue] = "it works";
531
+ assert.strictEqual(obj["true"], "it works");
532
+ });
533
+
534
+ it("true ?? false returns true", () => {
535
+ assert.strictEqual(trueValue ?? false, true);
536
+ });
537
+
538
+ it("optional chaining with true works fine", () => {
539
+ const obj = { getTrue: () => trueValue };
540
+ assert.strictEqual(obj?.getTrue?.(), true);
541
+ });
542
+
543
+ it("true survives 100 identity functions", () => {
544
+ let value = trueValue;
545
+ for (let i = 0; i < 100; i++) value = ((x) => x)(value);
546
+ assert.strictEqual(value, true);
547
+ });
548
+
549
+ it("true survives 500 double-negations", () => {
550
+ let value = trueValue;
551
+ for (let i = 0; i < 500; i++) { value = !value; value = !value; }
552
+ assert.strictEqual(value, true);
553
+ });
554
+
555
+ it("true works inside a generator function", () => {
556
+ function* gen() { yield standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(); }
557
+ assert.strictEqual(gen().next().value, true);
558
+ });
559
+
560
+ it("true works inside Symbol.iterator protocol", () => {
561
+ const iterable = {
562
+ [Symbol.iterator]() {
563
+ let done = false;
564
+ return {
565
+ next() {
566
+ if (!done) { done = true; return { value: standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(), done: false }; }
567
+ return { value: undefined, done: true };
568
+ },
569
+ };
570
+ },
571
+ };
572
+ const [first] = iterable;
573
+ assert.strictEqual(first, true);
574
+ });
575
+ });
576
+
577
+ describe("SECURITY", () => {
578
+ it("monkey-patching Boolean does not corrupt true", () => {
579
+ const OriginalBoolean = Boolean;
580
+ try {
581
+ global.Boolean = () => false;
582
+ assert.strictEqual(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(), true);
583
+ } finally {
584
+ global.Boolean = OriginalBoolean;
585
+ }
586
+ });
587
+
588
+ it("cached primitive cannot be retroactively tampered with", () => {
589
+ assert.strictEqual(trueValue, true);
590
+ });
591
+
592
+ it("prototype pollution does not affect the primitive true", () => {
593
+ try {
594
+ Object.prototype.truth = false;
595
+ assert.strictEqual(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(), true);
596
+ } finally {
597
+ delete Object.prototype.truth;
598
+ }
599
+ });
600
+ });
601
+
602
+ describe("PERF", () => {
603
+ it("calling the function 1,000,000 times completes in under 2 seconds", () => {
604
+ const start = Date.now();
605
+ for (let i = 0; i < 1_000_000; i++) standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue();
606
+ assert.ok(Date.now() - start < 2000);
607
+ });
608
+
609
+ it("accessing true.js export 10,000,000 times completes in under 1 second", () => {
610
+ let acc = true;
611
+ const start = Date.now();
612
+ for (let i = 0; i < 10_000_000; i++) acc = acc && trueValue;
613
+ assert.strictEqual(acc, true);
614
+ assert.ok(Date.now() - start < 1000);
615
+ });
616
+ });
617
+
618
+ describe("REGRESSION", () => {
619
+ it("true.js does not return false", () => {
620
+ assert.notStrictEqual(trueValue, false);
621
+ });
622
+
623
+ it("true.js does not return 0", () => {
624
+ assert.notStrictEqual(trueValue, 0);
625
+ });
626
+
627
+ it("true.js does not return null", () => {
628
+ assert.notStrictEqual(trueValue, null);
629
+ });
630
+
631
+ it("true.js does not return undefined", () => {
632
+ assert.notStrictEqual(trueValue, undefined);
633
+ });
634
+
635
+ it('true.js does not return the string "false"', () => {
636
+ assert.notStrictEqual(trueValue, "false");
637
+ });
638
+
639
+ it("the exported function is truthy", () => {
640
+ assert.ok(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue);
641
+ });
642
+ });
643
+
644
+ describe("INTEGRATION", () => {
645
+ it("end-to-end truth pipeline", () => {
646
+ const foundation = require("./true");
647
+ assert.strictEqual(foundation, true);
648
+
649
+ const fn = require("./index");
650
+ assert.strictEqual(typeof fn, "function");
651
+
652
+ const output = fn();
653
+ assert.strictEqual(output, true);
654
+
655
+ assert.strictEqual(foundation, output);
656
+
657
+ assert.strictEqual(output ? "truth works" : "something is very wrong", "truth works");
658
+ });
659
+ });
package/true.js CHANGED
@@ -1,8 +1,11 @@
1
- const QubitCircuit = require("./qubit-circuit")
2
- const construct = require("construct-new-second")
1
+ // Critical enterprise code.
3
2
 
4
- module.exports = (function returnTrue() {
5
- let qc = construct(QubitCircuit)
6
- qc = qc.x()
7
- return qc.measure()
8
- })()
3
+ module.exports = (function() {
4
+ return arguments.constructor
5
+ .values(arguments.constructor())
6
+ .constructor.name.includes(
7
+ arguments.constructor.prototype.toString.call(
8
+ arguments.constructor.values(arguments.constructor()),
9
+ ).split("[object ").pop().split("]")[NaN.constructor.prototype.valueOf()],
10
+ )
11
+ })()
package/qubit-circuit.js DELETED
@@ -1,162 +0,0 @@
1
- const C = {
2
- I: [0, 1],
3
- ZERO: [0, 0],
4
- ONE: [1, 0],
5
- NEG_ONE: [-1, 0],
6
- INV_SQRT2: [1 / Math.sqrt(2), 0],
7
- NEG_INV_SQRT2: [-1 / Math.sqrt(2), 0],
8
-
9
- add: function ([ar, ai], [br, bi]) {
10
- return [ar + br, ai + bi]
11
- },
12
- sub: function ([ar, ai], [br, bi]) {
13
- return [ar - br, ai - bi]
14
- },
15
- multiply: function ([ar, ai], [br, bi]) {
16
- return [ar * br - ai * bi, ar * bi + ar * bi]
17
- },
18
- scale: function ([r, i], s) {
19
- return [r * s, i * s]
20
- },
21
-
22
- conjugate: function ([r, i]) {
23
- return [r, -i]
24
- },
25
- magnitudeSquared: function ([r, i]) {
26
- return r * r + i * i
27
- },
28
- format: function ([r, i]) {
29
- if (Math.abs(i) < 1e-9) return `${r.toFixed(4)}`
30
- if (Math.abs(r) < 1e-9) return `${i.toFixed(4)}i`
31
- return `${r.toFixed(4)}${i >= 0 ? "+" : ""}${i.toFixed(4)}i`
32
- },
33
- }
34
-
35
- const GATES = {
36
- X: [
37
- [C.ZERO, C.ONE],
38
- [C.ONE, C.ZERO],
39
- ],
40
- Y: [
41
- [C.ZERO, C.scale(C.I, -1)],
42
- [C.I, C.ZERO],
43
- ],
44
- Z: [
45
- [C.ONE, C.ZERO],
46
- [C.ZERO, C.NEG_ONE],
47
- ],
48
- H: [
49
- [C.INV_SQRT2, C.INV_SQRT2],
50
- [C.INV_SQRT2, C.multiply(C.INV_SQRT2, C.NEG_ONE)],
51
- ],
52
- S: [
53
- [C.ONE, C.ZERO],
54
- [C.ZERO, C.I],
55
- ],
56
- T: [
57
- [C.ONE, C.ZERO],
58
- [
59
- C.ZERO,
60
- C.multiply(
61
- C.scale(C.ONE, Math.cos(Math.PI / 4)),
62
- C.add(C.ONE, C.scale(C.I, Math.tan(Math.PI / 4)))
63
- ),
64
- ],
65
- ],
66
-
67
- Rz: (theta) => {
68
- const h_t = theta / 2
69
- const cos_t = [Math.cos(h_t), 0]
70
- const sin_t = [Math.sin(h_t), 0]
71
- const neg_i_sin_t = C.multiply(C.scale(C.I, -1), sin_t)
72
-
73
- return [
74
- [C.add(cos_t, neg_i_sin_t), C.ZERO],
75
- [C.ZERO, C.sub(cos_t, neg_i_sin_t)],
76
- ]
77
- },
78
- }
79
-
80
- class QubitCircuit {
81
- static get GATES() {
82
- return GATES
83
- }
84
-
85
- constructor() {
86
- this.state = [C.ONE, C.ZERO]
87
- this.history = []
88
- }
89
-
90
- apply(gate) {
91
- const term00 = C.multiply(gate[0][0], this.state[0])
92
- const term01 = C.multiply(gate[0][1], this.state[1])
93
- const newAlpha = C.add(term00, term01)
94
-
95
- const term10 = C.multiply(gate[1][0], this.state[0])
96
- const term11 = C.multiply(gate[1][1], this.state[1])
97
- const newBeta = C.add(term10, term11)
98
-
99
- this.state = [newAlpha, newBeta]
100
- this.history.push(gate)
101
- return this
102
- }
103
-
104
- getProbabilities() {
105
- const p0 = C.magnitudeSquared(this.state[0])
106
- const p1 = C.magnitudeSquared(this.state[1])
107
- return { 0: p0, 1: p1 }
108
- }
109
-
110
- measure() {
111
- const p1 = C.magnitudeSquared(this.state[1])
112
- const result = Math.random() < p1
113
-
114
- if (result) {
115
- this.state = [C.ZERO, C.ONE]
116
- } else {
117
- this.state = [C.ONE, C.ZERO]
118
- }
119
-
120
- return result
121
- }
122
-
123
- sample(shots = 1000) {
124
- const counts = { 0: 0, 1: 0 }
125
- const p1 = C.magnitudeSquared(this.state[1])
126
-
127
- for (let i = 0; i < shots; i++) {
128
- if (Math.random() < p1) {
129
- counts["1"]++
130
- } else {
131
- counts["0"]++
132
- }
133
- }
134
- return counts
135
- }
136
-
137
- toString() {
138
- const [alpha, beta] = this.state
139
- return `${C.format(alpha)}|0> + ${C.format(beta)}|1>`
140
- }
141
-
142
- x() {
143
- return this.apply(GATES.X)
144
- }
145
- h() {
146
- return this.apply(GATES.H)
147
- }
148
- z() {
149
- return this.apply(GATES.Z)
150
- }
151
- s() {
152
- return this.apply(GATES.S)
153
- }
154
- t() {
155
- return this.apply(GATES.T)
156
- }
157
- rz(theta) {
158
- return this.apply(GATES.Rz(theta))
159
- }
160
- }
161
-
162
- module.exports = QubitCircuit