Helpers

generateHash.mjs

@mr_ozio/scraper-utils · v2.5.0 · Generated April 21, 2026

Target Style

Target Style

1 exports

const

hashOf

Target Style
export const hashOf = (contents, { using }) => crypto.createHash(using).update(contents).digest('hex')

Generates a hexadecimal hash using named options.

Target style API. Preferred for new code.

Parameters

  • contentsstring | Buffer
  • options{ using: string }

Returns

string

Example

const digest = hashOf('hello', {
  using: 'sha256',
})

Legacy Style

Legacy Style

3 exports

const

generateHash

Legacy Style
export const generateHash = (algorithm, contents) => hashOf(contents, { using: algorithm })

Generates a hexadecimal hash using the selected algorithm.

Legacy API. Kept for older code and not the preferred choice for new code.

Parameters

  • algorithmstring
  • contentsstring | Buffer

Returns

string

const

generateHashSHA256

Legacy Style
export const generateHashSHA256 = (contents) => hashOf(contents, { using: 'sha256' })

Generates a SHA-256 hash.

Legacy API. Kept for older code and not the preferred choice for new code.

Parameters

  • contentsstring | Buffer

Returns

string

const

generateHashMD5

Legacy Style
export const generateHashMD5 = (contents) => hashOf(contents, { using: 'md5' })

Generates an MD5 hash.

Legacy API. Kept for older code and not the preferred choice for new code.

Parameters

  • contentsstring | Buffer

Returns

string