totinyhash

tiny hash generator

Usage no npm install needed!

<script type="module">
  import totinyhash from 'https://cdn.skypack.dev/totinyhash';
</script>

README

Tinyhash

tiny hash generator

  • no dependency
  • fast and tiny (about 1k in gzip)
  • ready for wabpack css-loader as a custom getLocalIdent

Installation

# npm
npm install totinyhash
# yarn
yarn add totinyhash

How to use

const hashed = totinyhash("tinyhash")
// hashed equal "tRXXS"
  • First argument: Input

    • type: String
    • default: null
const hashed = totinyhash("tinyhash", ["z", "s", "x", "w", "y", "r", "v", "t", "u", "q"])
// hashed equal "tWZZT"
  • Second argument: HashMap

    • type: Array
    • default: ['x', 't', 'z', 'r', 'y', 'w', 'v', 's', 'q', 'u']

Test

yarn test
  • default
 PASS  test/default.test.js
  ✓ null to equal false
  ✓ "" to equal false
  ✓ "tinyhash" to equal "tRXXS"
  ✓ "long string with space and $,@ chars and 10,50 numbers" to equal "lswsaca15nQXRZW"
  • custom-hash
 PASS  test/custom-hash.test.js
  ✓ "tinyhash" to equal "tWZZT"
  • css-loader
 PASS  test/css-loader.test.js
  ✓ "my-component" to equal "mcVXYZ"
  ✓ "my-component__light" to equal "mclTRXZW"
  ✓ "my-component--container" to equal "mccZXWXV"
  ✓ "my-component--container__dark" to equal "mccdZUWTZ"