Skip to content

Commit

Permalink
add short hash to hame
Browse files Browse the repository at this point in the history
  • Loading branch information
wclr committed Jun 27, 2020
1 parent e43dd99 commit ba435af
Show file tree
Hide file tree
Showing 7 changed files with 436 additions and 362 deletions.
40 changes: 27 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
{
"name": "lp-loader",
"version": "1.0.0-pre.1",
"version": "1.0.0-pre.2",
"description": "Frictionless language packs for Webpack.",
"keywords": ["i18n", "l10n", "webpack", "loader", "dictionary", "languages"],
"scripts": {
"wp3-build": "ts-node-dev webpack3/build",
"prettier": {
"semi": false,
"singleQuote": true,
"arrowParens": "avoid"
},
"keywords": [
"i18n",
"l10n",
"webpack",
"loader",
"dictionary",
"languages"
],
"scripts": {
"wp3-build": "ts-node-dev webpack3/build",
"wp3-watch": "h --n lp-loader-wp3 -- ts-node-dev webpack3/watch",
"wp3-wds": "h --n lp-loader-wp3-wds -- ts-node-dev webpack3/wds",
"wp4-build": "ts-node-dev webpack4/build",
"wp3-wds": "h --n lp-loader-wp3-wds -- ts-node-dev webpack3/wds",
"wp4-build": "ts-node-dev --respawn webpack4/build",
"wp4-watch": "h --n lp-loader-wp4 -- ts-node-dev webpack4/watch",
"wp4-wds": "h --n lp-loader-wp4-wds -- ts-node-dev webpack4/wds",
"wp5-build": "ts-node-dev webpack5/build",
"wp4-wds": "ts-node-dev webpack4/wds",
"wp5-build": "ts-node-dev webpack5/build",
"wp5-watch": "h --n lp-loader-wp5 -- ts-node-dev webpack4/watch",
"wp5-wds": "h --n lp-loader-wp5-wds -- ts-node-dev webpack4/wds",
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "tsc"
},
"author": "whitecolor",
"files": [
"lib/lp-loader.*"
"lib/*"
],
"main": "./lib/lp-loader",
"loader": "./lib/lp-loader",
Expand All @@ -29,12 +41,14 @@
"@types/es6-shim": "0.0.31",
"@types/express": "^4.0.32",
"@types/node": "^8.0.25",
"@types/systemjs": "^0.19.30",
"@types/systemjs": "^0.19.30",
"get-port": "^5.1.1",
"minihost": "^0.4.1",
"node-static": "^0.7.9",
"ts-node": "^3.3.0",
"ts-node-dev": "^1.0.0-pre.4",
"typescript": "^2.4.2",
"open": "^7.0.4",
"ts-node": "^8.10.2",
"ts-node-dev": "^1.0.0-pre.49",
"typescript": "^3.9.5",
"xstream": "^10.9.0"
},
"license": "MIT"
Expand Down
12 changes: 12 additions & 0 deletions src/hash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as crypto from 'crypto'

const fullHashes: { [S: string]: string } = {}
const usedShortHashes: { [H: string]: string } = {}

export const getShortHash = (str: string, len = 4): string => {
const hash =
fullHashes[str] || crypto.createHash('md5').update(str).digest('hex')
const short = hash.slice(0, len)
usedShortHashes[short] = usedShortHashes[short] || str
return usedShortHashes[short] === str ? short : getShortHash(str, len + 1)
}
Loading

0 comments on commit ba435af

Please sign in to comment.