codekingpro/portable-devtools
114k
1const crypto = require('node:crypto')
2const { dirname, basename, resolve } = require('node:path')
3
4// use sha1 because it's faster, and collisions extremely unlikely anyway
5const pathSafeHash = s =>
6 crypto.createHash('sha1')
7 .update(s)
8 .digest('base64')
9 .replace(/[^a-zA-Z0-9]+/g, '')
10 .slice(0, 8)
11
12const retirePath = from => {
13 const d = dirname(from)
14 const b = basename(from)
15 const hash = pathSafeHash(from)
16 return resolve(d, `.${b}-${hash}`)
17}
18
19module.exports = retirePath
20 