Skip to content

Commit cc97a58

Browse files
committed
Add types, etc.
1 parent 0f3a499 commit cc97a58

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

crosshash.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type JSONValue =
2+
| string
3+
| number
4+
| boolean
5+
| { [x: string]: JSONValue }
6+
| Array<JSONValue>
7+
8+
export declare function crosshash(obj: JSONValue): string;
9+
10+
export declare function crossjson(obj: JSONValue): string;
11+
12+
export declare class CrossHashError extends Error {}

crosshash.js

+8-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class CrossHashError extends Error {
1515
const crosshash = (obj) => {
1616
return md5(crossjson(obj))
1717
}
18-
1918
const crossjson = (obj) => {
2019
return stringify(obj, {replacer: replacer})
2120
}
@@ -46,24 +45,19 @@ const main = () => {
4645
Usage:
4746
node crosshash.js --json '{"foo": "bar"}'
4847
node crosshash.js --hash '{"foo": "bar"}'
49-
`;
50-
51-
const args = process.argv.slice(2); // remove the first two arguments (node and script name)
52-
48+
`
49+
const args = process.argv.slice(2)
5350
if (args.length !== 2 || !['--json', '--hash'].includes(args[0])) {
54-
console.log(usage);
55-
process.exit(1);
51+
console.log(usage)
52+
process.exit(1)
5653
}
57-
58-
const action = args[0];
59-
const inputJson = JSON.parse(args[1]);
54+
const action = args[0]
55+
const inputJson = JSON.parse(args[1])
6056
const operation = {
6157
'--json': crossjson,
6258
'--hash': crosshash
63-
}[action];
64-
65-
const output = operation(inputJson);
66-
return output;
59+
}[action]
60+
return operation(inputJson)
6761
}
6862

6963
if (typeof require !== 'undefined' && typeof module !== 'undefined' && require.main === module) {

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
22
"name": "crosshash",
3-
"version": "0.2.0",
3+
"version": "0.3.1",
44
"description": "Stable, cross-platform JSON serialization and hashing for Python and JavaScript.",
55
"homepage": "https://github.com/httpie/crosshash",
66
"license": "MIT",
77
"main": "crosshash.js",
8+
"types": "crosshash.d.ts",
89
"files": [
9-
"crosshash.js"
10+
"crosshash.js",
11+
"crosshash.d.ts"
1012
],
1113
"bin": {
1214
"crosshash": "./crosshash.js",

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "crosshash"
3-
version = "0.2.0"
3+
version = "0.3.1"
44
authors = ["Jakub Roztocil <[email protected]>"]
55
description = "Stable, cross-platform JSON serialization and hashing for Python and JavaScript."
66
license = "MIT"

0 commit comments

Comments
 (0)