Skip to content

Commit

Permalink
chore: edit formating
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr committed Jun 28, 2023
1 parent e12a38f commit 60f32b7
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 117 deletions.
12 changes: 8 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = tab
indent_size = 4
insert_final_newline = true
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{json,yml,yaml,md}]
indent_style = space
3 changes: 2 additions & 1 deletion bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ suite(
},

['object-identity :: hashed']() {
const hasher = (val) => createHash('sha1').update(val).digest('hex');
const hasher = (val) =>
createHash('sha1').update(val).digest('hex');

return (o) => identify(o, hasher);
},
Expand Down
12 changes: 6 additions & 6 deletions bench/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"type": "module",
"dependencies": {
"@marais/bench": "0.0.8",
"object-hash": "^3.0.0",
"object-identity": "file:.."
}
"type": "module",
"dependencies": {
"@marais/bench": "0.0.8",
"object-hash": "^3.0.0",
"object-identity": "file:.."
}
}
84 changes: 38 additions & 46 deletions bench/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 41 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{
"name": "object-identity",
"version": "0.1.1",
"repository": "maraisr/object-identity",
"license": "MIT",
"author": "Marais Rossow <me@marais.dev> (https://marais.io)",
"sideEffects": false,
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.mjs",
"require": "./index.js"
},
"./package.json": "./package.json"
},
"main": "index.js",
"module": "index.mjs",
"types": "index.d.ts",
"files": [
"index.js",
"index.mjs",
"index.d.ts"
],
"scripts": {
"bench": "node bench/index.js",
"build": "bundt --minify",
"format": "prettier --write .",
"test": "uvu src \".test.ts$\" -r tsm",
"typecheck": "tsc --noEmit"
},
"prettier": "@marais/prettier",
"devDependencies": {
"@marais/prettier": "0.0.2",
"@marais/tsconfig": "0.0.4",
"bundt": "2.0.0-next.5",
"tsm": "2.3.0",
"typescript": "5.1.3",
"uvu": "0.5.4"
},
"volta": {
"node": "18.16.1"
}
"name": "object-identity",
"version": "0.1.1",
"repository": "maraisr/object-identity",
"license": "MIT",
"author": "Marais Rossow <me@marais.dev> (https://marais.io)",
"sideEffects": false,
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.mjs",
"require": "./index.js"
},
"./package.json": "./package.json"
},
"main": "index.js",
"module": "index.mjs",
"types": "index.d.ts",
"files": [
"index.js",
"index.mjs",
"index.d.ts"
],
"scripts": {
"bench": "node bench/index.js",
"build": "bundt --minify",
"format": "prettier --write .",
"test": "uvu src \".test.ts$\" -r tsm",
"typecheck": "tsc --noEmit"
},
"prettier": "@marais/prettier",
"devDependencies": {
"@marais/prettier": "0.0.4",
"@marais/tsconfig": "0.0.4",
"bundt": "2.0.0-next.5",
"tsm": "2.3.0",
"typescript": "5.1.3",
"uvu": "0.5.4"
},
"volta": {
"node": "18.16.1"
}
}
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ Objects('basic', () => {
});

Objects('key ordering', () => {
assert.equal(identify({ one: 'one', two: 'two' }), identify({ two: 'two', one: 'one' }));
assert.equal(
identify({ one: 'one', two: 'two' }),
identify({ two: 'two', one: 'one' }),
);
});

Objects('complex keys', () => {
Expand Down Expand Up @@ -129,7 +132,10 @@ Objects('same hash for Map or Object', () => {
const Sets = suite('set');

Sets('shouldnt be ordered', () => {
assert.not.equal(identify(new Set([1, 2, 3])), identify(new Set([3, 2, 1])));
assert.not.equal(
identify(new Set([1, 2, 3])),
identify(new Set([3, 2, 1])),
);
});

Sets('shouldnt be ordered', () => {
Expand Down Expand Up @@ -185,7 +191,11 @@ const Values = suite('values');

Values('primitives', () => {
const t = (v: any) =>
assert.equal(identify(v), identify(v), `Value ${v} should have hashed correctly.`);
assert.equal(
identify(v),
identify(v),
`Value ${v} should have hashed correctly.`,
);

t('test');
t(new Date());
Expand Down
17 changes: 14 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ function walk(input: any, ref_index: number) {
let type = Object.prototype.toString.call(input);

if (input == null || typeof input !== 'object') return String(input);
if (!(type === '[object RegExp]' || type === '[object Date]') && seen.has(input))
if (
!(type === '[object RegExp]' || type === '[object Date]') &&
seen.has(input)
)
return seen.get(input)!;
seen.set(input, '~' + ++ref_index);

Expand All @@ -26,15 +29,23 @@ function walk(input: any, ref_index: number) {
{
out += 'o';
tmp = Object.keys(input).sort();
for (; i < tmp.length; out += tmp[i] + walk(input[tmp[i++]], ref_index));
for (
;
i < tmp.length;
out += tmp[i] + walk(input[tmp[i++]], ref_index)
);
}
break;

case '[object Map]':
{
out += 'o';
tmp = Array.from((input as Map<string, unknown>).keys()).sort();
for (; i < tmp.length; out += tmp[i] + walk(input.get(tmp[i++]), ref_index));
for (
;
i < tmp.length;
out += tmp[i] + walk(input.get(tmp[i++]), ref_index)
);
}
break;

Expand Down
18 changes: 9 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"extends": "@marais/tsconfig",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"object-identity": ["src/index.d.ts"]
}
},
"include": ["src", "test"],
"exclude": ["node_modules"]
"extends": "@marais/tsconfig",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"object-identity": ["src/index.d.ts"]
}
},
"include": ["src", "test"],
"exclude": ["node_modules"]
}

0 comments on commit 60f32b7

Please sign in to comment.