JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 24254
  • Score
    100M100P100Q145529F
  • License MIT

A Base32-Crockford encoded API Key generator, validator, and converter to turn UUIDs into human readable API Keys

Package Exports

  • uuid-apikey

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (uuid-apikey) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

uuid-apikey

Actual version published on npm Travis build status Total npm module downloads

A Base32-Crockford encoded API Key generator, validator, and converter to turn UUIDs into human readable API Keys

API Keys are 31 characters in length (e.g. XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX), are fully-uppercase, tricky characters are treated equivalently (0 = O / 1 = L = I ), and the letter U is omitted to avoid common profanities.

A common use for this library is to allow APIKeys to be stored in a host DB as UUID, but to display the APIKey version in its encoded form to users.

Installation

You can install uuid-apikey with NPM.

npm install uuid-apikey

Usage

const uuidAPIKey = require('uuid-apikey');

console.log(uuidAPIKey.create());

Output:

{ uuid: '0b9ca335-92a8-46d8-b477-eb2ed83ac927',
  apiKey: '1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X' }

Reference

.isUUID(uuid)

Tests if the UUID string passed is a valid UUID.

uuidAPIKey.isUUID('0b9ca335-92a8-46d8-b477-eb2ed83ac927');
uuidAPIKey.isUUID('NodeJS');
true
false

.isAPIKey(apiKey)

Tests if the API Key string passed is a valid API Key.

uuidAPIKey.isAPIKey('1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X');
uuidAPIKey.isAPIKey('NodeJS');
true
false

.toAPIKey(uuid)

Converts a valid UUID into an API Key. Throws a TypeError if the UUID is invalid.

uuidAPIKey.toAPIKey('0b9ca335-92a8-46d8-b477-eb2ed83ac927');
'1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X'

.toUUID(apiKey)

Converts a valid API Key into an UUID. Throws a TypeError if the API Key is invalid.

uuidAPIKey.toUUID('1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X');
'0b9ca335-92a8-46d8-b477-eb2ed83ac927'

.check(apiKey, uuid)

Test that an API Key and a UUID are identical. Throws a TypeError if either the API Key or the UUID is invalid.

uuidAPIKey.check('1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X', '0b9ca335-92a8-46d8-b477-eb2ed83ac927');
true

.create()

Returns a new UUID and API Key pair

uuidAPIKey.create();
{ uuid: '0b9ca335-92a8-46d8-b477-eb2ed83ac927',
  apiKey: '1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X' }

License

MIT