Welcome to mirror list, hosted at ThFree Co, Russian Federation.

retire-path.js « lib « arborist « workspaces - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c7a4a319e27981034cab8c23ea64417cc0fde0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const crypto = require('crypto')
const { dirname, basename, resolve } = require('path')

// use sha1 because it's faster, and collisions extremely unlikely anyway
const pathSafeHash = s =>
  crypto.createHash('sha1')
    .update(s)
    .digest('base64')
    .replace(/[^a-zA-Z0-9]+/g, '')
    .slice(0, 8)

const retirePath = from => {
  const d = dirname(from)
  const b = basename(from)
  const hash = pathSafeHash(from)
  return resolve(d, `.${b}-${hash}`)
}

module.exports = retirePath