true-value 3.0.2 → 3.0.3
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/.github/workflows/lint.yml +20 -0
- package/eslint.config.mjs +3 -0
- package/index.js +4 -2
- package/package.json +4 -2
- package/test.js +458 -351
- package/true.js +14 -9
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: 10xly Code Quality
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["**"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ["**"]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
quality-check:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: "25"
|
|
17
|
+
- name: Install
|
|
18
|
+
run: npm install
|
|
19
|
+
- name: Run 10xly Lint
|
|
20
|
+
run: npx eslint . --max-warnings 0
|
package/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
// Import the secondary file in this library that exports the general boolean value true directly.
|
|
2
|
+
const trueValue = require("./true")
|
|
2
3
|
|
|
3
4
|
// Declare the standard JavaScript function that returns the general boolean value true.
|
|
4
5
|
function standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue() {
|
|
5
|
-
|
|
6
|
+
// Generally return the standard boolean value true.
|
|
7
|
+
return trueValue
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
// Export the standard JavaScript function that returns the general boolean value true.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "true-value",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "True",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jsfruit",
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
"test": "mocha test.js"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"mocha": "^11.7.5"
|
|
35
|
+
"mocha": "^11.7.5",
|
|
36
|
+
"@10xly/eslint-config": "*",
|
|
37
|
+
"eslint": "^9.39.3"
|
|
36
38
|
}
|
|
37
39
|
}
|
package/test.js
CHANGED
|
@@ -1,659 +1,766 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable */
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
3
|
+
"use strict"
|
|
4
|
+
|
|
5
|
+
const assert = require("assert")
|
|
6
|
+
const trueValue = require("./true")
|
|
7
|
+
const standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue = require("./index")
|
|
6
8
|
|
|
7
9
|
describe("SMOKE", () => {
|
|
8
10
|
it("true.js can be required without throwing", () => {
|
|
9
|
-
assert.doesNotThrow(() => require("./true"))
|
|
10
|
-
})
|
|
11
|
+
assert.doesNotThrow(() => require("./true"))
|
|
12
|
+
})
|
|
11
13
|
|
|
12
14
|
it("index.js can be required without throwing", () => {
|
|
13
|
-
assert.doesNotThrow(() => require("./index"))
|
|
14
|
-
})
|
|
15
|
+
assert.doesNotThrow(() => require("./index"))
|
|
16
|
+
})
|
|
15
17
|
|
|
16
18
|
it("true.js exports something", () => {
|
|
17
|
-
assert.notStrictEqual(trueValue, undefined)
|
|
18
|
-
assert.notStrictEqual(trueValue, null)
|
|
19
|
-
})
|
|
19
|
+
assert.notStrictEqual(trueValue, undefined)
|
|
20
|
+
assert.notStrictEqual(trueValue, null)
|
|
21
|
+
})
|
|
20
22
|
|
|
21
23
|
it("index.js exports something", () => {
|
|
22
|
-
assert.notStrictEqual(
|
|
23
|
-
|
|
24
|
+
assert.notStrictEqual(
|
|
25
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue,
|
|
26
|
+
undefined,
|
|
27
|
+
)
|
|
28
|
+
})
|
|
24
29
|
|
|
25
30
|
it("the exported item from index.js is a function", () => {
|
|
26
|
-
assert.strictEqual(
|
|
27
|
-
|
|
31
|
+
assert.strictEqual(
|
|
32
|
+
typeof standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue,
|
|
33
|
+
"function",
|
|
34
|
+
)
|
|
35
|
+
})
|
|
28
36
|
|
|
29
37
|
it("calling the function does not throw", () => {
|
|
30
|
-
assert.doesNotThrow(() =>
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
assert.doesNotThrow(() =>
|
|
39
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
40
|
+
)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
33
43
|
|
|
34
44
|
describe("TYPE", () => {
|
|
35
45
|
it("true.js exports a boolean", () => {
|
|
36
|
-
assert.strictEqual(typeof trueValue, "boolean")
|
|
37
|
-
})
|
|
46
|
+
assert.strictEqual(typeof trueValue, "boolean")
|
|
47
|
+
})
|
|
38
48
|
|
|
39
49
|
it("the function return value is a boolean", () => {
|
|
40
|
-
assert.strictEqual(
|
|
41
|
-
|
|
50
|
+
assert.strictEqual(
|
|
51
|
+
typeof standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
52
|
+
"boolean",
|
|
53
|
+
)
|
|
54
|
+
})
|
|
42
55
|
|
|
43
56
|
it("true.js export is not a number", () => {
|
|
44
|
-
assert.notStrictEqual(typeof trueValue, "number")
|
|
45
|
-
})
|
|
57
|
+
assert.notStrictEqual(typeof trueValue, "number")
|
|
58
|
+
})
|
|
46
59
|
|
|
47
60
|
it("true.js export is not a string", () => {
|
|
48
|
-
assert.notStrictEqual(typeof trueValue, "string")
|
|
49
|
-
})
|
|
61
|
+
assert.notStrictEqual(typeof trueValue, "string")
|
|
62
|
+
})
|
|
50
63
|
|
|
51
64
|
it("true.js export is not an object", () => {
|
|
52
|
-
assert.notStrictEqual(typeof trueValue, "object")
|
|
53
|
-
})
|
|
65
|
+
assert.notStrictEqual(typeof trueValue, "object")
|
|
66
|
+
})
|
|
54
67
|
|
|
55
68
|
it("true.js export is not undefined", () => {
|
|
56
|
-
assert.notStrictEqual(typeof trueValue, "undefined")
|
|
57
|
-
})
|
|
69
|
+
assert.notStrictEqual(typeof trueValue, "undefined")
|
|
70
|
+
})
|
|
58
71
|
|
|
59
72
|
it("true.js export is not a symbol", () => {
|
|
60
|
-
assert.notStrictEqual(typeof trueValue, "symbol")
|
|
61
|
-
})
|
|
73
|
+
assert.notStrictEqual(typeof trueValue, "symbol")
|
|
74
|
+
})
|
|
62
75
|
|
|
63
76
|
it("true.js export is not a bigint", () => {
|
|
64
|
-
assert.notStrictEqual(typeof trueValue, "bigint")
|
|
65
|
-
})
|
|
77
|
+
assert.notStrictEqual(typeof trueValue, "bigint")
|
|
78
|
+
})
|
|
66
79
|
|
|
67
80
|
it("true.js export is not a function", () => {
|
|
68
|
-
assert.notStrictEqual(typeof trueValue, "function")
|
|
69
|
-
})
|
|
70
|
-
})
|
|
81
|
+
assert.notStrictEqual(typeof trueValue, "function")
|
|
82
|
+
})
|
|
83
|
+
})
|
|
71
84
|
|
|
72
85
|
describe("VALUE", () => {
|
|
73
86
|
it("true.js strictly equals true", () => {
|
|
74
|
-
assert.strictEqual(trueValue, true)
|
|
75
|
-
})
|
|
87
|
+
assert.strictEqual(trueValue, true)
|
|
88
|
+
})
|
|
76
89
|
|
|
77
90
|
it("function return strictly equals true", () => {
|
|
78
|
-
assert.strictEqual(
|
|
79
|
-
|
|
91
|
+
assert.strictEqual(
|
|
92
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
93
|
+
true,
|
|
94
|
+
)
|
|
95
|
+
})
|
|
80
96
|
|
|
81
97
|
it("true.js does NOT strictly equal false", () => {
|
|
82
|
-
assert.notStrictEqual(trueValue, false)
|
|
83
|
-
})
|
|
98
|
+
assert.notStrictEqual(trueValue, false)
|
|
99
|
+
})
|
|
84
100
|
|
|
85
101
|
it("true.js does NOT strictly equal 1", () => {
|
|
86
|
-
assert.notStrictEqual(trueValue, 1)
|
|
87
|
-
})
|
|
102
|
+
assert.notStrictEqual(trueValue, 1)
|
|
103
|
+
})
|
|
88
104
|
|
|
89
105
|
it('true.js does NOT strictly equal "true"', () => {
|
|
90
|
-
assert.notStrictEqual(trueValue, "true")
|
|
91
|
-
})
|
|
106
|
+
assert.notStrictEqual(trueValue, "true")
|
|
107
|
+
})
|
|
92
108
|
|
|
93
109
|
it("true.js does NOT strictly equal 0", () => {
|
|
94
|
-
assert.notStrictEqual(trueValue, 0)
|
|
95
|
-
})
|
|
110
|
+
assert.notStrictEqual(trueValue, 0)
|
|
111
|
+
})
|
|
96
112
|
|
|
97
113
|
it("true.js does NOT strictly equal null", () => {
|
|
98
|
-
assert.notStrictEqual(trueValue, null)
|
|
99
|
-
})
|
|
114
|
+
assert.notStrictEqual(trueValue, null)
|
|
115
|
+
})
|
|
100
116
|
|
|
101
117
|
it("true.js does NOT strictly equal undefined", () => {
|
|
102
|
-
assert.notStrictEqual(trueValue, undefined)
|
|
103
|
-
})
|
|
118
|
+
assert.notStrictEqual(trueValue, undefined)
|
|
119
|
+
})
|
|
104
120
|
|
|
105
121
|
it("true.js does NOT strictly equal NaN", () => {
|
|
106
|
-
assert.notStrictEqual(trueValue, NaN)
|
|
107
|
-
})
|
|
122
|
+
assert.notStrictEqual(trueValue, NaN)
|
|
123
|
+
})
|
|
108
124
|
|
|
109
125
|
it("true.js does NOT strictly equal an empty string", () => {
|
|
110
|
-
assert.notStrictEqual(trueValue, "")
|
|
111
|
-
})
|
|
126
|
+
assert.notStrictEqual(trueValue, "")
|
|
127
|
+
})
|
|
112
128
|
|
|
113
129
|
it("true.js does NOT strictly equal an empty array", () => {
|
|
114
|
-
assert.notStrictEqual(trueValue, [])
|
|
115
|
-
})
|
|
130
|
+
assert.notStrictEqual(trueValue, [])
|
|
131
|
+
})
|
|
116
132
|
|
|
117
133
|
it("true.js does NOT strictly equal an empty object", () => {
|
|
118
|
-
assert.notStrictEqual(trueValue, {})
|
|
119
|
-
})
|
|
134
|
+
assert.notStrictEqual(trueValue, {})
|
|
135
|
+
})
|
|
120
136
|
|
|
121
137
|
it("true.js does NOT strictly equal Infinity", () => {
|
|
122
|
-
assert.notStrictEqual(trueValue, Infinity)
|
|
123
|
-
})
|
|
138
|
+
assert.notStrictEqual(trueValue, Infinity)
|
|
139
|
+
})
|
|
124
140
|
|
|
125
141
|
it("true.js does NOT strictly equal -Infinity", () => {
|
|
126
|
-
assert.notStrictEqual(trueValue, -Infinity)
|
|
127
|
-
})
|
|
142
|
+
assert.notStrictEqual(trueValue, -Infinity)
|
|
143
|
+
})
|
|
128
144
|
|
|
129
145
|
it("true.js does NOT strictly equal -1", () => {
|
|
130
|
-
assert.notStrictEqual(trueValue, -1)
|
|
131
|
-
})
|
|
132
|
-
})
|
|
146
|
+
assert.notStrictEqual(trueValue, -1)
|
|
147
|
+
})
|
|
148
|
+
})
|
|
133
149
|
|
|
134
150
|
describe("LOGIC", () => {
|
|
135
151
|
it("true && true === true", () => {
|
|
136
|
-
assert.strictEqual(trueValue && trueValue, true)
|
|
137
|
-
})
|
|
152
|
+
assert.strictEqual(trueValue && trueValue, true)
|
|
153
|
+
})
|
|
138
154
|
|
|
139
155
|
it("true || false === true", () => {
|
|
140
|
-
assert.strictEqual(trueValue || false, true)
|
|
141
|
-
})
|
|
156
|
+
assert.strictEqual(trueValue || false, true)
|
|
157
|
+
})
|
|
142
158
|
|
|
143
159
|
it("!true === false", () => {
|
|
144
|
-
assert.strictEqual(!trueValue, false)
|
|
145
|
-
})
|
|
160
|
+
assert.strictEqual(!trueValue, false)
|
|
161
|
+
})
|
|
146
162
|
|
|
147
163
|
it("!!true === true", () => {
|
|
148
|
-
assert.strictEqual(!!trueValue, true)
|
|
149
|
-
})
|
|
164
|
+
assert.strictEqual(!!trueValue, true)
|
|
165
|
+
})
|
|
150
166
|
|
|
151
167
|
it("true && false === false", () => {
|
|
152
|
-
assert.strictEqual(trueValue && false, false)
|
|
153
|
-
})
|
|
168
|
+
assert.strictEqual(trueValue && false, false)
|
|
169
|
+
})
|
|
154
170
|
|
|
155
171
|
it("true || true === true", () => {
|
|
156
|
-
assert.strictEqual(trueValue || true, true)
|
|
157
|
-
})
|
|
172
|
+
assert.strictEqual(trueValue || true, true)
|
|
173
|
+
})
|
|
158
174
|
|
|
159
175
|
it("false || true === true", () => {
|
|
160
|
-
assert.strictEqual(false || trueValue, true)
|
|
161
|
-
})
|
|
176
|
+
assert.strictEqual(false || trueValue, true)
|
|
177
|
+
})
|
|
162
178
|
|
|
163
179
|
it("true XOR false === 1 (via bitwise)", () => {
|
|
164
|
-
assert.strictEqual((trueValue ^ false) === 1, true)
|
|
165
|
-
})
|
|
180
|
+
assert.strictEqual((trueValue ^ false) === 1, true)
|
|
181
|
+
})
|
|
166
182
|
|
|
167
183
|
it("true XOR true === 0 (via bitwise)", () => {
|
|
168
|
-
assert.strictEqual((trueValue ^ true) === 0, true)
|
|
169
|
-
})
|
|
184
|
+
assert.strictEqual((trueValue ^ true) === 0, true)
|
|
185
|
+
})
|
|
170
186
|
|
|
171
187
|
it("true in a ternary selects the first branch", () => {
|
|
172
|
-
assert.strictEqual(trueValue ? "correct" : "incorrect", "correct")
|
|
173
|
-
})
|
|
188
|
+
assert.strictEqual(trueValue ? "correct" : "incorrect", "correct")
|
|
189
|
+
})
|
|
174
190
|
|
|
175
191
|
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
|
-
})
|
|
192
|
+
let entered = false
|
|
193
|
+
if (trueValue) entered = true
|
|
194
|
+
assert.strictEqual(entered, true)
|
|
195
|
+
})
|
|
180
196
|
|
|
181
197
|
it("true used in while loop runs exactly once (with break)", () => {
|
|
182
|
-
let count = 0
|
|
183
|
-
while (trueValue) {
|
|
184
|
-
|
|
185
|
-
|
|
198
|
+
let count = 0
|
|
199
|
+
while (trueValue) {
|
|
200
|
+
count++
|
|
201
|
+
break
|
|
202
|
+
}
|
|
203
|
+
assert.strictEqual(count, 1)
|
|
204
|
+
})
|
|
186
205
|
|
|
187
206
|
it("Boolean(true) === true", () => {
|
|
188
|
-
assert.strictEqual(Boolean(trueValue), true)
|
|
189
|
-
})
|
|
207
|
+
assert.strictEqual(Boolean(trueValue), true)
|
|
208
|
+
})
|
|
190
209
|
|
|
191
210
|
it("true in a switch statement matches case true", () => {
|
|
192
|
-
let matched = false
|
|
211
|
+
let matched = false
|
|
193
212
|
switch (trueValue) {
|
|
194
|
-
case true:
|
|
195
|
-
|
|
213
|
+
case true:
|
|
214
|
+
matched = true
|
|
215
|
+
break
|
|
216
|
+
default:
|
|
217
|
+
matched = false
|
|
196
218
|
}
|
|
197
|
-
assert.strictEqual(matched, true)
|
|
198
|
-
})
|
|
199
|
-
})
|
|
219
|
+
assert.strictEqual(matched, true)
|
|
220
|
+
})
|
|
221
|
+
})
|
|
200
222
|
|
|
201
223
|
describe("COERCION", () => {
|
|
202
224
|
it("true + 0 === 1", () => {
|
|
203
|
-
assert.strictEqual(trueValue + 0, 1)
|
|
204
|
-
})
|
|
225
|
+
assert.strictEqual(trueValue + 0, 1)
|
|
226
|
+
})
|
|
205
227
|
|
|
206
228
|
it("true + 1 === 2", () => {
|
|
207
|
-
assert.strictEqual(trueValue + 1, 2)
|
|
208
|
-
})
|
|
229
|
+
assert.strictEqual(trueValue + 1, 2)
|
|
230
|
+
})
|
|
209
231
|
|
|
210
232
|
it('true + "" === "true"', () => {
|
|
211
|
-
assert.strictEqual(trueValue + "", "true")
|
|
212
|
-
})
|
|
233
|
+
assert.strictEqual(trueValue + "", "true")
|
|
234
|
+
})
|
|
213
235
|
|
|
214
236
|
it('String(true) === "true"', () => {
|
|
215
|
-
assert.strictEqual(String(trueValue), "true")
|
|
216
|
-
})
|
|
237
|
+
assert.strictEqual(String(trueValue), "true")
|
|
238
|
+
})
|
|
217
239
|
|
|
218
240
|
it("Number(true) === 1", () => {
|
|
219
|
-
assert.strictEqual(Number(trueValue), 1)
|
|
220
|
-
})
|
|
241
|
+
assert.strictEqual(Number(trueValue), 1)
|
|
242
|
+
})
|
|
221
243
|
|
|
222
244
|
it("parseInt(true) is NaN", () => {
|
|
223
|
-
assert.ok(isNaN(parseInt(trueValue)))
|
|
224
|
-
})
|
|
245
|
+
assert.ok(isNaN(parseInt(trueValue)))
|
|
246
|
+
})
|
|
225
247
|
|
|
226
248
|
it("true > false", () => {
|
|
227
|
-
assert.ok(trueValue > false)
|
|
228
|
-
})
|
|
249
|
+
assert.ok(trueValue > false)
|
|
250
|
+
})
|
|
229
251
|
|
|
230
252
|
it("true >= true", () => {
|
|
231
|
-
assert.ok(trueValue >= true)
|
|
232
|
-
})
|
|
253
|
+
assert.ok(trueValue >= true)
|
|
254
|
+
})
|
|
233
255
|
|
|
234
256
|
it("true * 1 === 1", () => {
|
|
235
|
-
assert.strictEqual(trueValue * 1, 1)
|
|
236
|
-
})
|
|
257
|
+
assert.strictEqual(trueValue * 1, 1)
|
|
258
|
+
})
|
|
237
259
|
|
|
238
260
|
it("true * 0 === 0", () => {
|
|
239
|
-
assert.strictEqual(trueValue * 0, 0)
|
|
240
|
-
})
|
|
261
|
+
assert.strictEqual(trueValue * 0, 0)
|
|
262
|
+
})
|
|
241
263
|
|
|
242
264
|
it("true / 1 === 1", () => {
|
|
243
|
-
assert.strictEqual(trueValue / 1, 1)
|
|
244
|
-
})
|
|
265
|
+
assert.strictEqual(trueValue / 1, 1)
|
|
266
|
+
})
|
|
245
267
|
|
|
246
268
|
it("true - true === 0", () => {
|
|
247
|
-
assert.strictEqual(trueValue - trueValue, 0)
|
|
248
|
-
})
|
|
269
|
+
assert.strictEqual(trueValue - trueValue, 0)
|
|
270
|
+
})
|
|
249
271
|
|
|
250
272
|
it("[true].join() === 'true'", () => {
|
|
251
|
-
assert.strictEqual([trueValue].join(), "true")
|
|
252
|
-
})
|
|
273
|
+
assert.strictEqual([trueValue].join(), "true")
|
|
274
|
+
})
|
|
253
275
|
|
|
254
276
|
it("JSON.stringify(true) === 'true'", () => {
|
|
255
|
-
assert.strictEqual(JSON.stringify(trueValue), "true")
|
|
256
|
-
})
|
|
277
|
+
assert.strictEqual(JSON.stringify(trueValue), "true")
|
|
278
|
+
})
|
|
257
279
|
|
|
258
280
|
it("JSON round-trip preserves true", () => {
|
|
259
|
-
assert.strictEqual(JSON.parse(JSON.stringify(trueValue)), true)
|
|
260
|
-
})
|
|
261
|
-
})
|
|
281
|
+
assert.strictEqual(JSON.parse(JSON.stringify(trueValue)), true)
|
|
282
|
+
})
|
|
283
|
+
})
|
|
262
284
|
|
|
263
285
|
describe("PROTO", () => {
|
|
264
286
|
it("Object(true) is a Boolean instance", () => {
|
|
265
|
-
assert.ok(Object(trueValue) instanceof Boolean)
|
|
266
|
-
})
|
|
287
|
+
assert.ok(Object(trueValue) instanceof Boolean)
|
|
288
|
+
})
|
|
267
289
|
|
|
268
290
|
it("Boolean.prototype.valueOf.call(true) === true", () => {
|
|
269
|
-
assert.strictEqual(Boolean.prototype.valueOf.call(trueValue), true)
|
|
270
|
-
})
|
|
291
|
+
assert.strictEqual(Boolean.prototype.valueOf.call(trueValue), true)
|
|
292
|
+
})
|
|
271
293
|
|
|
272
294
|
it("Boolean.prototype.toString.call(true) === 'true'", () => {
|
|
273
|
-
assert.strictEqual(Boolean.prototype.toString.call(trueValue), "true")
|
|
274
|
-
})
|
|
295
|
+
assert.strictEqual(Boolean.prototype.toString.call(trueValue), "true")
|
|
296
|
+
})
|
|
275
297
|
|
|
276
298
|
it("Object.is(true, true) === true", () => {
|
|
277
|
-
assert.ok(Object.is(trueValue, true))
|
|
278
|
-
})
|
|
299
|
+
assert.ok(Object.is(trueValue, true))
|
|
300
|
+
})
|
|
279
301
|
|
|
280
302
|
it("Object.is(true, 1) === false", () => {
|
|
281
|
-
assert.ok(!Object.is(trueValue, 1))
|
|
282
|
-
})
|
|
303
|
+
assert.ok(!Object.is(trueValue, 1))
|
|
304
|
+
})
|
|
283
305
|
|
|
284
306
|
it("Object.is(true, false) === false", () => {
|
|
285
|
-
assert.ok(!Object.is(trueValue, false))
|
|
286
|
-
})
|
|
307
|
+
assert.ok(!Object.is(trueValue, false))
|
|
308
|
+
})
|
|
287
309
|
|
|
288
310
|
it("boxed true has no own enumerable properties", () => {
|
|
289
|
-
assert.deepStrictEqual(Object.keys(Object(trueValue)), [])
|
|
290
|
-
})
|
|
291
|
-
})
|
|
311
|
+
assert.deepStrictEqual(Object.keys(Object(trueValue)), [])
|
|
312
|
+
})
|
|
313
|
+
})
|
|
292
314
|
|
|
293
315
|
describe("ARRAY", () => {
|
|
294
316
|
it("[true].includes(true)", () => {
|
|
295
|
-
assert.ok([trueValue].includes(true))
|
|
296
|
-
})
|
|
317
|
+
assert.ok([trueValue].includes(true))
|
|
318
|
+
})
|
|
297
319
|
|
|
298
320
|
it("[true].indexOf(true) === 0", () => {
|
|
299
|
-
assert.strictEqual([trueValue].indexOf(true), 0)
|
|
300
|
-
})
|
|
321
|
+
assert.strictEqual([trueValue].indexOf(true), 0)
|
|
322
|
+
})
|
|
301
323
|
|
|
302
324
|
it("[true].find(x => x === true) === true", () => {
|
|
303
|
-
assert.strictEqual(
|
|
304
|
-
|
|
325
|
+
assert.strictEqual(
|
|
326
|
+
[trueValue].find((x) => x === true),
|
|
327
|
+
true,
|
|
328
|
+
)
|
|
329
|
+
})
|
|
305
330
|
|
|
306
331
|
it("[true].every(x => x === true)", () => {
|
|
307
|
-
assert.ok([trueValue].every((x) => x === true))
|
|
308
|
-
})
|
|
332
|
+
assert.ok([trueValue].every((x) => x === true))
|
|
333
|
+
})
|
|
309
334
|
|
|
310
335
|
it("[true].some(x => x === true)", () => {
|
|
311
|
-
assert.ok([trueValue].some((x) => x === true))
|
|
312
|
-
})
|
|
336
|
+
assert.ok([trueValue].some((x) => x === true))
|
|
337
|
+
})
|
|
313
338
|
|
|
314
339
|
it("[true].filter(x => x === true) has length 1", () => {
|
|
315
|
-
assert.strictEqual([trueValue].filter((x) => x === true).length, 1)
|
|
316
|
-
})
|
|
340
|
+
assert.strictEqual([trueValue].filter((x) => x === true).length, 1)
|
|
341
|
+
})
|
|
317
342
|
|
|
318
343
|
it("[true].map(x => !x) deep equals [false]", () => {
|
|
319
|
-
assert.deepStrictEqual(
|
|
320
|
-
|
|
344
|
+
assert.deepStrictEqual(
|
|
345
|
+
[trueValue].map((x) => !x),
|
|
346
|
+
[false],
|
|
347
|
+
)
|
|
348
|
+
})
|
|
321
349
|
|
|
322
350
|
it("[true].reduce((a, b) => a && b, true) === true", () => {
|
|
323
|
-
assert.strictEqual(
|
|
324
|
-
|
|
351
|
+
assert.strictEqual(
|
|
352
|
+
[trueValue].reduce((a, b) => a && b, true),
|
|
353
|
+
true,
|
|
354
|
+
)
|
|
355
|
+
})
|
|
325
356
|
|
|
326
357
|
it("Array.from([true])[0] === true", () => {
|
|
327
|
-
assert.strictEqual(Array.from([trueValue])[0], true)
|
|
328
|
-
})
|
|
329
|
-
})
|
|
358
|
+
assert.strictEqual(Array.from([trueValue])[0], true)
|
|
359
|
+
})
|
|
360
|
+
})
|
|
330
361
|
|
|
331
362
|
describe("SET", () => {
|
|
332
363
|
it("a Set containing true has size 1", () => {
|
|
333
|
-
assert.strictEqual(new Set([trueValue]).size, 1)
|
|
334
|
-
})
|
|
364
|
+
assert.strictEqual(new Set([trueValue]).size, 1)
|
|
365
|
+
})
|
|
335
366
|
|
|
336
367
|
it("a Set containing true has(true)", () => {
|
|
337
|
-
assert.ok(new Set([trueValue]).has(true))
|
|
338
|
-
})
|
|
368
|
+
assert.ok(new Set([trueValue]).has(true))
|
|
369
|
+
})
|
|
339
370
|
|
|
340
371
|
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
|
-
})
|
|
372
|
+
const s = new Set()
|
|
373
|
+
s.add(trueValue)
|
|
374
|
+
s.add(trueValue)
|
|
375
|
+
assert.strictEqual(s.size, 1)
|
|
376
|
+
})
|
|
377
|
+
})
|
|
347
378
|
|
|
348
379
|
describe("MAP", () => {
|
|
349
380
|
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
|
-
})
|
|
381
|
+
const m = new Map()
|
|
382
|
+
m.set(trueValue, "yes")
|
|
383
|
+
assert.strictEqual(m.get(true), "yes")
|
|
384
|
+
})
|
|
385
|
+
})
|
|
355
386
|
|
|
356
387
|
describe("FUNCTION", () => {
|
|
357
388
|
it("has the correct name", () => {
|
|
358
389
|
assert.strictEqual(
|
|
359
390
|
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue.name,
|
|
360
|
-
"standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue"
|
|
361
|
-
)
|
|
362
|
-
})
|
|
391
|
+
"standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue",
|
|
392
|
+
)
|
|
393
|
+
})
|
|
363
394
|
|
|
364
395
|
it("has length 0", () => {
|
|
365
|
-
assert.strictEqual(
|
|
366
|
-
|
|
396
|
+
assert.strictEqual(
|
|
397
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue.length,
|
|
398
|
+
0,
|
|
399
|
+
)
|
|
400
|
+
})
|
|
367
401
|
|
|
368
402
|
it("calling with no arguments returns true", () => {
|
|
369
|
-
assert.strictEqual(
|
|
370
|
-
|
|
403
|
+
assert.strictEqual(
|
|
404
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
405
|
+
true,
|
|
406
|
+
)
|
|
407
|
+
})
|
|
371
408
|
|
|
372
409
|
it("calling with one argument still returns true", () => {
|
|
373
|
-
assert.strictEqual(
|
|
374
|
-
|
|
410
|
+
assert.strictEqual(
|
|
411
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(false),
|
|
412
|
+
true,
|
|
413
|
+
)
|
|
414
|
+
})
|
|
375
415
|
|
|
376
416
|
it("calling with many falsy arguments still returns true", () => {
|
|
377
417
|
assert.strictEqual(
|
|
378
|
-
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
418
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(
|
|
419
|
+
false,
|
|
420
|
+
null,
|
|
421
|
+
undefined,
|
|
422
|
+
NaN,
|
|
423
|
+
0,
|
|
424
|
+
"",
|
|
425
|
+
[],
|
|
426
|
+
{},
|
|
427
|
+
-1,
|
|
428
|
+
),
|
|
429
|
+
true,
|
|
430
|
+
)
|
|
431
|
+
})
|
|
382
432
|
|
|
383
433
|
it("calling 1000 times always returns true", () => {
|
|
384
|
-
const results = Array.from({ length: 1000 }, () =>
|
|
385
|
-
|
|
386
|
-
|
|
434
|
+
const results = Array.from({ length: 1000 }, () =>
|
|
435
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
436
|
+
)
|
|
437
|
+
assert.ok(results.every((r) => r === true))
|
|
438
|
+
})
|
|
387
439
|
|
|
388
440
|
it("is callable via .call()", () => {
|
|
389
|
-
assert.strictEqual(
|
|
390
|
-
|
|
441
|
+
assert.strictEqual(
|
|
442
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue.call(
|
|
443
|
+
null,
|
|
444
|
+
),
|
|
445
|
+
true,
|
|
446
|
+
)
|
|
447
|
+
})
|
|
391
448
|
|
|
392
449
|
it("is callable via .apply()", () => {
|
|
393
|
-
assert.strictEqual(
|
|
394
|
-
|
|
450
|
+
assert.strictEqual(
|
|
451
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue.apply(
|
|
452
|
+
null,
|
|
453
|
+
[],
|
|
454
|
+
),
|
|
455
|
+
true,
|
|
456
|
+
)
|
|
457
|
+
})
|
|
395
458
|
|
|
396
459
|
it("is callable via .bind()()", () => {
|
|
397
|
-
assert.strictEqual(
|
|
398
|
-
|
|
460
|
+
assert.strictEqual(
|
|
461
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue.bind(
|
|
462
|
+
null,
|
|
463
|
+
)(),
|
|
464
|
+
true,
|
|
465
|
+
)
|
|
466
|
+
})
|
|
399
467
|
|
|
400
468
|
it("works wrapped in a closure", () => {
|
|
401
|
-
const getValue = () =>
|
|
402
|
-
|
|
403
|
-
|
|
469
|
+
const getValue = () =>
|
|
470
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue()
|
|
471
|
+
assert.strictEqual(getValue(), true)
|
|
472
|
+
})
|
|
404
473
|
|
|
405
474
|
it("works when passed to Array.prototype.map", () => {
|
|
406
475
|
assert.deepStrictEqual(
|
|
407
|
-
[1, 2, 3].map(() =>
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
476
|
+
[1, 2, 3].map(() =>
|
|
477
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
478
|
+
),
|
|
479
|
+
[true, true, true],
|
|
480
|
+
)
|
|
481
|
+
})
|
|
411
482
|
|
|
412
483
|
it("works when passed to Array.prototype.filter", () => {
|
|
413
484
|
assert.deepStrictEqual(
|
|
414
|
-
[1, 2, 3].filter(() =>
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
485
|
+
[1, 2, 3].filter(() =>
|
|
486
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
487
|
+
),
|
|
488
|
+
[1, 2, 3],
|
|
489
|
+
)
|
|
490
|
+
})
|
|
418
491
|
|
|
419
492
|
it("works inside a Promise", () => {
|
|
420
493
|
return Promise.resolve().then(() => {
|
|
421
|
-
assert.strictEqual(
|
|
422
|
-
|
|
423
|
-
|
|
494
|
+
assert.strictEqual(
|
|
495
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
496
|
+
true,
|
|
497
|
+
)
|
|
498
|
+
})
|
|
499
|
+
})
|
|
424
500
|
|
|
425
501
|
it("works inside async/await", async () => {
|
|
426
|
-
const result = await Promise.resolve(
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
502
|
+
const result = await Promise.resolve(
|
|
503
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
504
|
+
)
|
|
505
|
+
assert.strictEqual(result, true)
|
|
506
|
+
})
|
|
507
|
+
})
|
|
430
508
|
|
|
431
509
|
describe("MODULE", () => {
|
|
432
510
|
it("requiring true.js twice returns same value", () => {
|
|
433
|
-
assert.strictEqual(require("./true"), require("./true"))
|
|
434
|
-
})
|
|
511
|
+
assert.strictEqual(require("./true"), require("./true"))
|
|
512
|
+
})
|
|
435
513
|
|
|
436
514
|
it("requiring index.js twice returns same function reference", () => {
|
|
437
|
-
assert.strictEqual(require("./index"), require("./index"))
|
|
438
|
-
})
|
|
515
|
+
assert.strictEqual(require("./index"), require("./index"))
|
|
516
|
+
})
|
|
439
517
|
|
|
440
518
|
it("true cannot be corrupted by property assignment", () => {
|
|
441
|
-
const original = trueValue
|
|
442
|
-
try {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
519
|
+
const original = trueValue
|
|
520
|
+
try {
|
|
521
|
+
trueValue.hacked = "no"
|
|
522
|
+
} catch (e) {}
|
|
523
|
+
assert.strictEqual(require("./true"), original)
|
|
524
|
+
})
|
|
525
|
+
})
|
|
446
526
|
|
|
447
527
|
describe("COMPETITOR", () => {
|
|
448
528
|
it("our true equals Boolean(1)", () => {
|
|
449
|
-
assert.strictEqual(trueValue, Boolean(1))
|
|
450
|
-
})
|
|
529
|
+
assert.strictEqual(trueValue, Boolean(1))
|
|
530
|
+
})
|
|
451
531
|
|
|
452
532
|
it("our true equals !!1", () => {
|
|
453
|
-
assert.strictEqual(trueValue, !!1)
|
|
454
|
-
})
|
|
533
|
+
assert.strictEqual(trueValue, !!1)
|
|
534
|
+
})
|
|
455
535
|
|
|
456
536
|
it("our true equals !!{}", () => {
|
|
457
|
-
assert.strictEqual(trueValue, !!{})
|
|
458
|
-
})
|
|
537
|
+
assert.strictEqual(trueValue, !!{})
|
|
538
|
+
})
|
|
459
539
|
|
|
460
540
|
it('our true equals !!"nonempty"', () => {
|
|
461
|
-
assert.strictEqual(trueValue, !!"nonempty")
|
|
462
|
-
})
|
|
541
|
+
assert.strictEqual(trueValue, !!"nonempty")
|
|
542
|
+
})
|
|
463
543
|
|
|
464
544
|
it("our true equals (1 === 1)", () => {
|
|
465
|
-
assert.strictEqual(trueValue, 1 === 1)
|
|
466
|
-
})
|
|
545
|
+
assert.strictEqual(trueValue, 1 === 1)
|
|
546
|
+
})
|
|
467
547
|
|
|
468
548
|
it("our true equals Array.isArray([])", () => {
|
|
469
|
-
assert.strictEqual(trueValue, Array.isArray([]))
|
|
470
|
-
})
|
|
549
|
+
assert.strictEqual(trueValue, Array.isArray([]))
|
|
550
|
+
})
|
|
471
551
|
|
|
472
552
|
it("our true equals Number.isFinite(0)", () => {
|
|
473
|
-
assert.strictEqual(trueValue, Number.isFinite(0))
|
|
474
|
-
})
|
|
475
|
-
})
|
|
553
|
+
assert.strictEqual(trueValue, Number.isFinite(0))
|
|
554
|
+
})
|
|
555
|
+
})
|
|
476
556
|
|
|
477
557
|
describe("EDGE", () => {
|
|
478
558
|
it("true survives JSON round-trip through a nested object", () => {
|
|
479
|
-
const parsed = JSON.parse(
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
559
|
+
const parsed = JSON.parse(
|
|
560
|
+
JSON.stringify({
|
|
561
|
+
value: trueValue,
|
|
562
|
+
nested: { deeper: { truth: trueValue } },
|
|
563
|
+
}),
|
|
564
|
+
)
|
|
565
|
+
assert.strictEqual(parsed.value, true)
|
|
566
|
+
assert.strictEqual(parsed.nested.deeper.truth, true)
|
|
567
|
+
})
|
|
483
568
|
|
|
484
569
|
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
|
-
})
|
|
570
|
+
const store = {}
|
|
571
|
+
store.truth = trueValue
|
|
572
|
+
assert.strictEqual(store.truth, true)
|
|
573
|
+
})
|
|
489
574
|
|
|
490
575
|
it("true survives Object.assign", () => {
|
|
491
|
-
const target = {}
|
|
492
|
-
Object.assign(target, { truth: trueValue })
|
|
493
|
-
assert.strictEqual(target.truth, true)
|
|
494
|
-
})
|
|
576
|
+
const target = {}
|
|
577
|
+
Object.assign(target, { truth: trueValue })
|
|
578
|
+
assert.strictEqual(target.truth, true)
|
|
579
|
+
})
|
|
495
580
|
|
|
496
581
|
it("true survives spread operator", () => {
|
|
497
|
-
assert.strictEqual({ ...{ truth: trueValue } }.truth, true)
|
|
498
|
-
})
|
|
582
|
+
assert.strictEqual({ ...{ truth: trueValue } }.truth, true)
|
|
583
|
+
})
|
|
499
584
|
|
|
500
585
|
it("true survives structuredClone", () => {
|
|
501
|
-
assert.strictEqual(structuredClone({ truth: trueValue }).truth, true)
|
|
502
|
-
})
|
|
586
|
+
assert.strictEqual(structuredClone({ truth: trueValue }).truth, true)
|
|
587
|
+
})
|
|
503
588
|
|
|
504
589
|
it("true is truthy", () => {
|
|
505
|
-
assert.ok(trueValue)
|
|
506
|
-
})
|
|
590
|
+
assert.ok(trueValue)
|
|
591
|
+
})
|
|
507
592
|
|
|
508
593
|
it("!true is falsy", () => {
|
|
509
|
-
assert.ok(
|
|
510
|
-
})
|
|
594
|
+
assert.ok(!!trueValue)
|
|
595
|
+
})
|
|
511
596
|
|
|
512
597
|
it("true.toString() returns 'true'", () => {
|
|
513
|
-
assert.strictEqual(trueValue.toString(), "true")
|
|
514
|
-
})
|
|
598
|
+
assert.strictEqual(trueValue.toString(), "true")
|
|
599
|
+
})
|
|
515
600
|
|
|
516
601
|
it("true.valueOf() returns true", () => {
|
|
517
|
-
assert.strictEqual(trueValue.valueOf(), true)
|
|
518
|
-
})
|
|
602
|
+
assert.strictEqual(trueValue.valueOf(), true)
|
|
603
|
+
})
|
|
519
604
|
|
|
520
605
|
it("typeof true is 'boolean'", () => {
|
|
521
|
-
assert.strictEqual(typeof trueValue, "boolean")
|
|
522
|
-
})
|
|
606
|
+
assert.strictEqual(typeof trueValue, "boolean")
|
|
607
|
+
})
|
|
523
608
|
|
|
524
609
|
it("true as array index accesses index 1, not 0", () => {
|
|
525
|
-
assert.strictEqual([42][trueValue], undefined)
|
|
526
|
-
})
|
|
610
|
+
assert.strictEqual([42][trueValue], undefined)
|
|
611
|
+
})
|
|
527
612
|
|
|
528
613
|
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
|
-
})
|
|
614
|
+
const obj = {}
|
|
615
|
+
obj[trueValue] = "it works"
|
|
616
|
+
assert.strictEqual(obj["true"], "it works")
|
|
617
|
+
})
|
|
533
618
|
|
|
534
619
|
it("true ?? false returns true", () => {
|
|
535
|
-
assert.strictEqual(trueValue ?? false, true)
|
|
536
|
-
})
|
|
620
|
+
assert.strictEqual(trueValue ?? false, true)
|
|
621
|
+
})
|
|
537
622
|
|
|
538
623
|
it("optional chaining with true works fine", () => {
|
|
539
|
-
const obj = { getTrue: () => trueValue }
|
|
540
|
-
assert.strictEqual(obj?.getTrue?.(), true)
|
|
541
|
-
})
|
|
624
|
+
const obj = { getTrue: () => trueValue }
|
|
625
|
+
assert.strictEqual(obj?.getTrue?.(), true)
|
|
626
|
+
})
|
|
542
627
|
|
|
543
628
|
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
|
-
})
|
|
629
|
+
let value = trueValue
|
|
630
|
+
for (let i = 0; i < 100; i++) value = ((x) => x)(value)
|
|
631
|
+
assert.strictEqual(value, true)
|
|
632
|
+
})
|
|
548
633
|
|
|
549
634
|
it("true survives 500 double-negations", () => {
|
|
550
|
-
let value = trueValue
|
|
551
|
-
for (let i = 0; i < 500; i++) {
|
|
552
|
-
|
|
553
|
-
|
|
635
|
+
let value = trueValue
|
|
636
|
+
for (let i = 0; i < 500; i++) {
|
|
637
|
+
value = !value
|
|
638
|
+
value = !value
|
|
639
|
+
}
|
|
640
|
+
assert.strictEqual(value, true)
|
|
641
|
+
})
|
|
554
642
|
|
|
555
643
|
it("true works inside a generator function", () => {
|
|
556
|
-
function* gen() {
|
|
557
|
-
|
|
558
|
-
|
|
644
|
+
function* gen() {
|
|
645
|
+
yield standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue()
|
|
646
|
+
}
|
|
647
|
+
assert.strictEqual(gen().next().value, true)
|
|
648
|
+
})
|
|
559
649
|
|
|
560
650
|
it("true works inside Symbol.iterator protocol", () => {
|
|
561
651
|
const iterable = {
|
|
562
652
|
[Symbol.iterator]() {
|
|
563
|
-
let done = false
|
|
653
|
+
let done = false
|
|
564
654
|
return {
|
|
565
655
|
next() {
|
|
566
|
-
if (!done) {
|
|
567
|
-
|
|
656
|
+
if (!done) {
|
|
657
|
+
done = true
|
|
658
|
+
return {
|
|
659
|
+
value:
|
|
660
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
661
|
+
done: false,
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
return { value: undefined, done: true }
|
|
568
665
|
},
|
|
569
|
-
}
|
|
666
|
+
}
|
|
570
667
|
},
|
|
571
|
-
}
|
|
572
|
-
const [first] = iterable
|
|
573
|
-
assert.strictEqual(first, true)
|
|
574
|
-
})
|
|
575
|
-
})
|
|
668
|
+
}
|
|
669
|
+
const [first] = iterable
|
|
670
|
+
assert.strictEqual(first, true)
|
|
671
|
+
})
|
|
672
|
+
})
|
|
576
673
|
|
|
577
674
|
describe("SECURITY", () => {
|
|
578
675
|
it("monkey-patching Boolean does not corrupt true", () => {
|
|
579
|
-
const OriginalBoolean = Boolean
|
|
676
|
+
const OriginalBoolean = Boolean
|
|
580
677
|
try {
|
|
581
|
-
global.Boolean = () => false
|
|
582
|
-
assert.strictEqual(
|
|
678
|
+
global.Boolean = () => false
|
|
679
|
+
assert.strictEqual(
|
|
680
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
681
|
+
true,
|
|
682
|
+
)
|
|
583
683
|
} finally {
|
|
584
|
-
global.Boolean = OriginalBoolean
|
|
684
|
+
global.Boolean = OriginalBoolean
|
|
585
685
|
}
|
|
586
|
-
})
|
|
686
|
+
})
|
|
587
687
|
|
|
588
688
|
it("cached primitive cannot be retroactively tampered with", () => {
|
|
589
|
-
assert.strictEqual(trueValue, true)
|
|
590
|
-
})
|
|
689
|
+
assert.strictEqual(trueValue, true)
|
|
690
|
+
})
|
|
591
691
|
|
|
592
692
|
it("prototype pollution does not affect the primitive true", () => {
|
|
593
693
|
try {
|
|
594
|
-
Object.prototype.truth = false
|
|
595
|
-
assert.strictEqual(
|
|
694
|
+
Object.prototype.truth = false
|
|
695
|
+
assert.strictEqual(
|
|
696
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue(),
|
|
697
|
+
true,
|
|
698
|
+
)
|
|
596
699
|
} finally {
|
|
597
|
-
delete Object.prototype.truth
|
|
700
|
+
delete Object.prototype.truth
|
|
598
701
|
}
|
|
599
|
-
})
|
|
600
|
-
})
|
|
702
|
+
})
|
|
703
|
+
})
|
|
601
704
|
|
|
602
705
|
describe("PERF", () => {
|
|
603
706
|
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++)
|
|
606
|
-
|
|
607
|
-
|
|
707
|
+
const start = Date.now()
|
|
708
|
+
for (let i = 0; i < 1_000_000; i++)
|
|
709
|
+
standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue()
|
|
710
|
+
assert.ok(Date.now() - start < 2000)
|
|
711
|
+
})
|
|
608
712
|
|
|
609
713
|
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
|
-
})
|
|
714
|
+
let acc = true
|
|
715
|
+
const start = Date.now()
|
|
716
|
+
for (let i = 0; i < 10_000_000; i++) acc = acc && trueValue
|
|
717
|
+
assert.strictEqual(acc, true)
|
|
718
|
+
assert.ok(Date.now() - start < 1000)
|
|
719
|
+
})
|
|
720
|
+
})
|
|
617
721
|
|
|
618
722
|
describe("REGRESSION", () => {
|
|
619
723
|
it("true.js does not return false", () => {
|
|
620
|
-
assert.notStrictEqual(trueValue, false)
|
|
621
|
-
})
|
|
724
|
+
assert.notStrictEqual(trueValue, false)
|
|
725
|
+
})
|
|
622
726
|
|
|
623
727
|
it("true.js does not return 0", () => {
|
|
624
|
-
assert.notStrictEqual(trueValue, 0)
|
|
625
|
-
})
|
|
728
|
+
assert.notStrictEqual(trueValue, 0)
|
|
729
|
+
})
|
|
626
730
|
|
|
627
731
|
it("true.js does not return null", () => {
|
|
628
|
-
assert.notStrictEqual(trueValue, null)
|
|
629
|
-
})
|
|
732
|
+
assert.notStrictEqual(trueValue, null)
|
|
733
|
+
})
|
|
630
734
|
|
|
631
735
|
it("true.js does not return undefined", () => {
|
|
632
|
-
assert.notStrictEqual(trueValue, undefined)
|
|
633
|
-
})
|
|
736
|
+
assert.notStrictEqual(trueValue, undefined)
|
|
737
|
+
})
|
|
634
738
|
|
|
635
739
|
it('true.js does not return the string "false"', () => {
|
|
636
|
-
assert.notStrictEqual(trueValue, "false")
|
|
637
|
-
})
|
|
740
|
+
assert.notStrictEqual(trueValue, "false")
|
|
741
|
+
})
|
|
638
742
|
|
|
639
743
|
it("the exported function is truthy", () => {
|
|
640
|
-
assert.ok(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue)
|
|
641
|
-
})
|
|
642
|
-
})
|
|
744
|
+
assert.ok(standardJavaScriptFunctionThatReturnsTheGeneralBooleanValueTrue)
|
|
745
|
+
})
|
|
746
|
+
})
|
|
643
747
|
|
|
644
748
|
describe("INTEGRATION", () => {
|
|
645
749
|
it("end-to-end truth pipeline", () => {
|
|
646
|
-
const foundation = require("./true")
|
|
647
|
-
assert.strictEqual(foundation, true)
|
|
750
|
+
const foundation = require("./true")
|
|
751
|
+
assert.strictEqual(foundation, true)
|
|
648
752
|
|
|
649
|
-
const fn = require("./index")
|
|
650
|
-
assert.strictEqual(typeof fn, "function")
|
|
753
|
+
const fn = require("./index")
|
|
754
|
+
assert.strictEqual(typeof fn, "function")
|
|
651
755
|
|
|
652
|
-
const output = fn()
|
|
653
|
-
assert.strictEqual(output, true)
|
|
756
|
+
const output = fn()
|
|
757
|
+
assert.strictEqual(output, true)
|
|
654
758
|
|
|
655
|
-
assert.strictEqual(foundation, output)
|
|
759
|
+
assert.strictEqual(foundation, output)
|
|
656
760
|
|
|
657
|
-
assert.strictEqual(
|
|
658
|
-
|
|
659
|
-
|
|
761
|
+
assert.strictEqual(
|
|
762
|
+
output ? "truth works" : "something is very wrong",
|
|
763
|
+
"truth works",
|
|
764
|
+
)
|
|
765
|
+
})
|
|
766
|
+
})
|
package/true.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
// Critical enterprise code.
|
|
2
2
|
|
|
3
|
-
module.exports = (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
module.exports = (() =>
|
|
4
|
+
arguments.constructor
|
|
5
|
+
.values(arguments.constructor())
|
|
6
|
+
.constructor.name.includes(
|
|
7
|
+
// eslint-disable-next-line 10x-engineering/no-tostring
|
|
8
|
+
arguments.constructor.prototype.toString
|
|
9
|
+
.call(
|
|
10
|
+
arguments.constructor.values(arguments.constructor()),
|
|
11
|
+
)
|
|
12
|
+
.split("[object ")
|
|
13
|
+
.pop()
|
|
14
|
+
// eslint-disable-next-line unicorn/prefer-number-properties, 10x-engineering/no-valueof
|
|
15
|
+
.split("]")[NaN.constructor.prototype.valueOf()],
|
|
16
|
+
))()
|