Skip to content

Commit f74c0e8

Browse files
committed
refactor: use === instead of == for better performance
1 parent 1b314f2 commit f74c0e8

File tree

3 files changed

+49
-41
lines changed

3 files changed

+49
-41
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"devDependencies": {
2828
"@types/jest": "^28.1.3",
29+
"@types/node": "^22.14.0",
2930
"base64-url": "^2.3.3",
3031
"esbuild": "^0.12.28",
3132
"flattie": "^1.1.0",

pnpm-lock.yaml

Lines changed: 43 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let counter = 0
1717
export function stableHash(arg: any): string {
1818
const type = typeof arg
1919
const constructor = arg && arg.constructor
20-
const isDate = constructor == Date
20+
const isDate = constructor === Date
2121

2222
if (Object(arg) === arg && !isDate && constructor != RegExp) {
2323
// Object/function, not null/date/regexp. Use WeakMap to store the id first.
@@ -31,14 +31,14 @@ export function stableHash(arg: any): string {
3131
table.set(arg, result)
3232
let index: any
3333

34-
if (constructor == Array) {
34+
if (constructor === Array) {
3535
// Array.
3636
result = "@"
3737
for (index = 0; index < arg.length; index++) {
3838
result += stableHash(arg[index]) + ","
3939
}
4040
table.set(arg, result)
41-
} else if (constructor == Object) {
41+
} else if (constructor === Object) {
4242
// Object, sort keys.
4343
result = "#"
4444
const keys = Object.keys(arg).sort()
@@ -52,8 +52,8 @@ export function stableHash(arg: any): string {
5252
return result
5353
}
5454
if (isDate) return arg.toJSON()
55-
if (type == "symbol") return arg.toString()
56-
return type == "string" ? JSON.stringify(arg) : "" + arg
55+
if (type === "symbol") return arg.toString()
56+
return type === "string" ? JSON.stringify(arg) : "" + arg
5757
}
5858

5959
export default stableHash

0 commit comments

Comments
 (0)