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





"API Keys are for people"
This module is a generator, validator, and converter that transforms UUIDs into human-readable Base32-Crockford encoded API Keys.
It turns this:
```
9b3ac4c9-0228-4e42-a244-927059b1a5ea`
into this:`
KCXC9JD-08M4WGH-M9294W1-B6RTBTH
Base32-Crockford API Keys it avoids these problems by doing the following:
API Keys have no lower-case characters. The API Key parser handles all lower-case characters as their upper-case equivalent. (e.g. a ≡ A)*O
* API Keys do not use similar characters glyphs which can be confused in some typefaces. The parser handles confusing characters as the same values.
* the letters , o, and the number 0L
* the letters , l, I, i, and the number 1U
* API Keys do not use the letter which could inadvertently lead to common English profanities.
NOTE: This package makes use of ES6 and ES7 functionality. If you are using a version of node prior to version 8 then you will need to use a polyfill (e.g. babel) for compatibility.
with NPM.
`shell
npm install uuid-apikey
`
Usage
`es2016
const uuidAPIKey = require('uuid-apikey');console.log(uuidAPIKey.create());
`
Output:
`
{ uuid: '0b9ca335-92a8-46d8-b477-eb2ed83ac927',
apiKey: '1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X' }
`Command Line
uuid-apikey installs with a command line tool. The tool is available using the command apiKeyTool which can be install globally using:`
npm install uuid-apikey -g
`$3
`shell
$ apiKeyTool.js Usage: apiKeyTool [options]
Options:
-V, --version output the version number
-g, --generate Create a new API Key/UUID pair. Ignores other parameters if passed.
-u, --uuid UUID for operation. If no other parameter is passed this is converted to an API Key.
-a, --apikey API Key for operation. If no other parameter is passed this is converted to an UUID.
-c, --check Check the API Key and/or UUID provided are valid. If both API Key and UUID are passed then they are checked against each other.
-h, --help output usage information
`$3
#### Generation
`shell
$ apiKeyTool.js -g UUID(9b3ac4c9-0228-4e42-a244-927059b1a5ea)
APIKey(KCXC9JD-08M4WGH-M9294W1-B6RTBTH)
`
#### Conversion
`shell
$ apiKeyTool.js -a KCXC9JD-08M4WGH-M9294W1-B6RTBTH -u 9b3ac4c9-0228-4e42-a244-927059b1a5eaUUID(9b3ac4c9-0228-4e42-a244-927059b1a5ea) => APIKey(KCXC9JD-08M4WGH-M9294W1-B6RTBTH)
APIKey(KCXC9JD-08M4WGH-M9294W1-B6RTBTH) => UUID(9b3ac4c9-0228-4e42-a244-927059b1a5ea)
`#### Testing
`shell
$ apiKeyTool.js -a KCXC9JD-08M4WGH-M9294W1-B6RTBTH -u 9b3ac4c9-0228-4e42-a244-927059b1a5ea -cUUID(9b3ac4c9-0228-4e42-a244-927059b1a5ea) : valid
APIKey(KCXC9JD-08M4WGH-M9294W1-B6RTBTH) : valid
UUID & APIKey are identical : true
`API Reference
$3
Tests if the UUID string passed is a valid UUID.
`es2016
uuidAPIKey.isUUID('0b9ca335-92a8-46d8-b477-eb2ed83ac927');
uuidAPIKey.isUUID('NodeJS');
`
Output:
`
true
false
`$3
Tests if the API Key string passed is a valid API Key.
`es2016
uuidAPIKey.isAPIKey('1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X');
uuidAPIKey.isAPIKey('NodeJS');
`
Output:
`
true
false
`$3
Converts a valid UUID into an API Key. Throws a TypeError if the UUID is invalid.
`es2016
uuidAPIKey.toAPIKey('0b9ca335-92a8-46d8-b477-eb2ed83ac927');
uuidAPIKey.toAPIKey('0b9ca335-92a8-46d8-b477-eb2ed83ac927', { 'noDashes': true });
`
Output:
`
'1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X'
'1EEA6DCJAM4DP2PHVYPBNV0XCJ9X'
`
Options| Option | Type | Desc |
| ------ | ---- | ---- |
| noDashes | boolean | Generates an APIKey without dashes |
$3
Converts a valid API Key into an UUID. Throws a TypeError if the API Key is invalid.
`es2016
uuidAPIKey.toUUID('1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X');
`
Output:
`
'0b9ca335-92a8-46d8-b477-eb2ed83ac927'
`$3
Test that an API Key and a UUID are identical. Throws a TypeError if either the API Key or the UUID is invalid.
`es2016
uuidAPIKey.check('1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X', '0b9ca335-92a8-46d8-b477-eb2ed83ac927');
`
Output:
`
true
`$3
Returns a new UUID and API Key pair
`es2016
uuidAPIKey.create();
`
Output:
`
{ uuid: '0b9ca335-92a8-46d8-b477-eb2ed83ac927',
apiKey: '1EEA6DC-JAM4DP2-PHVYPBN-V0XCJ9X' }
``| Option | Type | Desc |
| ------ | ---- | ---- |
| noDashes | boolean | Generates an APIKey without dashes |