Socket
Socket
Sign inDemoInstall

hat

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hat

generate random IDs and avoid collisions


Version published
Weekly downloads
279K
increased by1.12%
Maintainers
1
Install size
7.12 kB
Created
Weekly downloads
 

Readme

Source

hat

Generate random IDs and avoid collisions.

hat

examples

hat

var hat = require('hat');

var id = hat();
console.log(id);

output:

0c82a54f22f775a3ed8b97b2dea74036

rack

var hat = require('hat');
var rack = hat.rack();

console.log(rack());
console.log(rack());

output:

1c24171393dc5de04ffcb21f1182ab28
fabe2323acc1b559dee43d4a1e16cbeb

methods

var hat = require('hat');

hat(bits=128, base=16)

Generate a random ID string with bits of data in a base.

Leading zeros are appended such that all outputs for a given number of bits have equal length.

var rack = hat.rack(bits=128, base=16, expandBy)

Make a new hat rack. Call rack() repeatedly to generate new IDs which are checked for collisions.

If expandBy is specified, increment bits by this amount if too many collisions occur. If expandBy isn't specified, rack() will throw if too many collisions occur during generation.

Optionally call var id = rack(data) to store data at the new ID.

You can get the data out again with rack.get(id) and set the data with rack.set(id, value).

Keywords

FAQs

Last updated on 06 Aug 2011

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc