fast-hash-code
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

npm npm travis

fast-hash-code

Generate a hash from a string, simple and fast.

Installation

yarn add fast-hash-code

Example

import fastHashCode from 'fast-hash-code'

fastHashCode('Hello World!') // -969099747

Options

  • forcePositive (new in v2.0.0) Description: Force the hash to be positive default: false note: The hash generated when true will be different from when false for the same string

    import fastHashCode from 'fast-hash-code'
    
    const hashPositive = fastHashCode('Hello World!', {
      forcePositive: true
    })
    
    console.log(hashPositive) // 1178383901
  • seed (new in v2.0.0) Description: Seed the hash, generate a different hash for each seed. default: 0

    import fastHashCode from 'fast-hash-code'
    
    const hashSeed = fastHashCode('Hello World!', {
      seed: 123
    })
    
    console.log(hashSeed) // 1597036056
  • caseSensitive (new in v2.0.0) Description: Force the hash to be case sensitive default: true

    import fastHashCode from 'fast-hash-code'
    
    const hashCaseSensitive = fastHashCode('Hello World!', {
      caseSensitive: false
    })
    
    console.log(hashCaseSensitive) // -217287203

References

https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/

Readme

Keywords

Package Sidebar

Install

npm i fast-hash-code

Weekly Downloads

541

Version

2.1.0

License

ISC

Unpacked Size

93.6 kB

Total Files

24

Last publish

Collaborators

  • alexandrehpiva