Skip to content

Commit b6b36bf

Browse files
committed
Use strict equality checks everywhere (=== and !==)
1 parent 17f07ec commit b6b36bf

85 files changed

Lines changed: 316 additions & 297 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/cli.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ function completer (text) {
9696
// scope variables
9797
for (const def in scope) {
9898
if (scope.hasOwnProperty(def)) {
99-
if (def.indexOf(keyword) == 0) {
99+
if (def.indexOf(keyword) === 0) {
100100
matches.push(def)
101101
}
102102
}
103103
}
104104

105105
// commandline keywords
106106
['exit', 'quit', 'clear'].forEach(function (cmd) {
107-
if (cmd.indexOf(keyword) == 0) {
107+
if (cmd.indexOf(keyword) === 0) {
108108
matches.push(cmd)
109109
}
110110
})
@@ -113,7 +113,7 @@ function completer (text) {
113113
const ignore = ['expr', 'type']
114114
for (const func in math) {
115115
if (math.hasOwnProperty(func)) {
116-
if (func.indexOf(keyword) == 0 && ignore.indexOf(func) == -1) {
116+
if (func.indexOf(keyword) === 0 && ignore.indexOf(func) === -1) {
117117
matches.push(func)
118118
}
119119
}
@@ -123,7 +123,7 @@ function completer (text) {
123123
const Unit = math.type.Unit
124124
for (let name in Unit.UNITS) {
125125
if (Unit.UNITS.hasOwnProperty(name)) {
126-
if (name.indexOf(keyword) == 0) {
126+
if (name.indexOf(keyword) === 0) {
127127
matches.push(name)
128128
}
129129
}
@@ -133,13 +133,13 @@ function completer (text) {
133133
const prefixes = Unit.PREFIXES[name]
134134
for (const prefix in prefixes) {
135135
if (prefixes.hasOwnProperty(prefix)) {
136-
if (prefix.indexOf(keyword) == 0) {
136+
if (prefix.indexOf(keyword) === 0) {
137137
matches.push(prefix)
138-
} else if (keyword.indexOf(prefix) == 0) {
138+
} else if (keyword.indexOf(prefix) === 0) {
139139
const unitKeyword = keyword.substring(prefix.length)
140140
for (const n in Unit.UNITS) {
141141
if (Unit.UNITS.hasOwnProperty(n)) {
142-
if (n.indexOf(unitKeyword) == 0 &&
142+
if (n.indexOf(unitKeyword) === 0 &&
143143
Unit.isValuelessUnit(prefix + n)) {
144144
matches.push(prefix + n)
145145
}
@@ -153,7 +153,7 @@ function completer (text) {
153153

154154
// remove duplicates
155155
matches = matches.filter(function (elem, pos, arr) {
156-
return arr.indexOf(elem) == pos
156+
return arr.indexOf(elem) === pos
157157
})
158158
}
159159

@@ -229,7 +229,7 @@ function runStream (input, output, mode, parenthesis) {
229229
if (node) {
230230
if (math.type.isAssignmentNode(node)) {
231231
const name = findSymbolName(node)
232-
if (name != null) {
232+
if (name !== null) {
233233
scope.ans = scope[name]
234234
console.log(name + ' = ' + format(scope[name]))
235235
} else {

docs/datatypes/numbers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ where:
8484
- `EPSILON` is the relative difference between x and y. Epsilon is configurable
8585
and is `1e-14` by default. See [Configuration](../core/configuration.md).
8686
- `DBL_EPSILON` is the minimum positive floating point number such that
87-
`1.0 + DBL_EPSILON != 1.0`. This is a constant with a value of approximately
87+
`1.0 + DBL_EPSILON !== 1.0`. This is a constant with a value of approximately
8888
`2.2204460492503130808472633361816e-16`.
8989

9090
Note that the relational functions cannot be used to compare small values
@@ -94,11 +94,11 @@ Examples:
9494

9595
```js
9696
// compare values having a round-off error
97-
console.log(0.1 + 0.2 == 0.3) // false
97+
console.log(0.1 + 0.2 === 0.3) // false
9898
console.log(math.equal(0.1 + 0.2, 0.3)) // true
9999

100100
// small values (< 2.22e-16) cannot be compared
101-
console.log(3e-20 == 3.1e-20) // false
101+
console.log(3e-20 === 3.1e-20) // false
102102
console.log(math.equal(3e-20, 3.1e-20)) // true
103103
```
104104

docs/expressions/customization.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ function customLaTeX(node, options) {
285285
return node.args[0].toTex(options) + ' plus ' + node.args[1].toTex(options)
286286
}
287287
else if (node.type === 'ConstantNode') {
288-
if (node.value == 0) {
288+
if (node.value === 0) {
289289
return '\\mbox{zero}'
290290
}
291-
else if (node.value == 1) {
291+
else if (node.value === 1) {
292292
return '\\mbox{one}'
293293
}
294-
else if (node.value == 2) {
294+
else if (node.value === 2) {
295295
return '\\mbox{two}'
296296
}
297297
else {

examples/advanced/expression_trees.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ console.log()
4545
console.log('Replace all symbol nodes "x" in expression "x^2 + 5*x" with a constant 3')
4646
const node2 = math.parse('x^2 + 5*x')
4747
const transformed = node2.transform(function (node, path, parent) {
48-
if (node.isSymbolNode && node.name == 'x') {
48+
if (node.isSymbolNode && node.name === 'x') {
4949
return new math.expression.node.ConstantNode(3)
5050
} else {
5151
return node

examples/browser/custom_separators.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
// replace the custom separators in the input with the default separators
6262
const expr = expression.value
6363
.replace(new RegExp('\\' + decimals.value + '|\\' + args.value, 'g'), function (match) {
64-
return match == decimals.value ? '.': ','
64+
return match === decimals.value ? '.': ','
6565
})
6666

6767
// do the actual evaluation
@@ -70,7 +70,7 @@
7070
// replace the default separators in the output with custom separators
7171
result.innerHTML = res.toString()
7272
.replace(new RegExp(',|\\.', 'g'), function (match) {
73-
return match == '.' ? decimals.value : args.value
73+
return match === '.' ? decimals.value : args.value
7474
})
7575
}
7676
</script>

src/error/ArgumentsError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function ArgumentsError (fn, count, min, max) {
2121

2222
this.message = 'Wrong number of arguments in function ' + fn +
2323
' (' + count + ' provided, ' +
24-
min + ((max != undefined) ? ('-' + max) : '') + ' expected)'
24+
min + ((max !== undefined && max !== null) ? ('-' + max) : '') + ' expected)'
2525

2626
this.stack = (new Error()).stack
2727
}

src/expression/node/Node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function factory (type, config, load, typed, math) {
128128
* ConstantNode with value 2:
129129
*
130130
* const res = Node.transform(function (node, path, parent) {
131-
* if (node && node.isSymbolNode) && (node.name == 'x')) {
131+
* if (node && node.isSymbolNode) && (node.name === 'x')) {
132132
* return new ConstantNode(2)
133133
* }
134134
* else {
@@ -160,7 +160,7 @@ function factory (type, config, load, typed, math) {
160160
* find all nodes of type SymbolNode having name 'x':
161161
*
162162
* const results = Node.filter(function (node) {
163-
* return (node && node.isSymbolNode) && (node.name == 'x')
163+
* return (node && node.isSymbolNode) && (node.name === 'x')
164164
* })
165165
*
166166
* @param {function(node: Node, path: string, parent: Node) : Node} callback

src/expression/node/OperatorNode.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ function factory (type, config, load, typed) {
379379

380380
// fall back to postfix
381381
return operand + this.op
382-
} else if (args.length == 2) {
382+
} else if (args.length === 2) {
383383
let lhs = args[0].toString(options) // left hand side
384384
let rhs = args[1].toString(options) // right hand side
385385
if (parens[0]) { // left hand side in parenthesis?
@@ -389,7 +389,7 @@ function factory (type, config, load, typed) {
389389
rhs = '(' + rhs + ')'
390390
}
391391

392-
if (this.implicit && (this.getIdentifier() === 'OperatorNode:multiply') && (implicit == 'hide')) {
392+
if (this.implicit && (this.getIdentifier() === 'OperatorNode:multiply') && (implicit === 'hide')) {
393393
return lhs + ' ' + rhs
394394
}
395395

@@ -467,7 +467,7 @@ function factory (type, config, load, typed) {
467467

468468
// fall back to postfix
469469
return '<span class="math-operator math-unary-operator math-righthand-unary-operator">' + escape(this.op) + '</span>' + operand
470-
} else if (args.length == 2) { // binary operatoes
470+
} else if (args.length === 2) { // binary operatoes
471471
let lhs = args[0].toHTML(options) // left hand side
472472
let rhs = args[1].toHTML(options) // right hand side
473473
if (parens[0]) { // left hand side in parenthesis?
@@ -477,7 +477,7 @@ function factory (type, config, load, typed) {
477477
rhs = '<span class="math-parenthesis math-round-parenthesis">(</span>' + rhs + '<span class="math-parenthesis math-round-parenthesis">)</span>'
478478
}
479479

480-
if (this.implicit && (this.getIdentifier() === 'OperatorNode:multiply') && (implicit == 'hide')) {
480+
if (this.implicit && (this.getIdentifier() === 'OperatorNode:multiply') && (implicit === 'hide')) {
481481
return lhs + '<span class="math-operator math-binary-operator math-implicit-binary-operator"></span>' + rhs
482482
}
483483

src/expression/node/SymbolNode.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,17 @@ function factory (type, config, load, typed, math) {
135135
SymbolNode.prototype.toHTML = function (options) {
136136
const name = escape(this.name)
137137

138-
if (name == 'true' || name == 'false') {
138+
if (name === 'true' || name === 'false') {
139139
return '<span class="math-symbol math-boolean">' + name + '</span>'
140-
} else if (name == 'i') {
140+
} else if (name === 'i') {
141141
return '<span class="math-symbol math-imaginary-symbol">' + name + '</span>'
142-
} else if (name == 'Infinity') {
142+
} else if (name === 'Infinity') {
143143
return '<span class="math-symbol math-infinity-symbol">' + name + '</span>'
144-
} else if (name == 'NaN') {
144+
} else if (name === 'NaN') {
145145
return '<span class="math-symbol math-nan-symbol">' + name + '</span>'
146-
} else if (name == 'null') {
146+
} else if (name === 'null') {
147147
return '<span class="math-symbol math-null-symbol">' + name + '</span>'
148-
} else if (name == 'undefined') {
148+
} else if (name === 'undefined') {
149149
return '<span class="math-symbol math-undefined-symbol">' + name + '</span>'
150150
}
151151

src/expression/transform/max.transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function factory (type, config, load, typed) {
1616
return typed('max', {
1717
'...any': function (args) {
1818
// change last argument dim from one-based to zero-based
19-
if (args.length == 2 && isCollection(args[0])) {
19+
if (args.length === 2 && isCollection(args[0])) {
2020
const dim = args[1]
2121
if (type.isNumber(dim)) {
2222
args[1] = dim - 1

0 commit comments

Comments
 (0)