Skip to content

Commit

Permalink
Updated eslint config and README.
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldenver committed Jul 20, 2022
1 parent 848c382 commit 3db8c58
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ module.exports = {
ignoreStrings: true,
ignoreTemplateLiterals: true,
}],
'semi': [ 'error', 'always' ],
'@typescript-eslint/no-explicit-any': 'off',
},
overrides: [
{
files: [ 'test/generate_api_key.spec.ts' ],
rules: {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/ban-ts-comment': [
'error',
{
Expand Down
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,24 @@ generation methods, such as `string`, `bytes`, `base32`, `base62`, `uuidv4`, and
`uuidv5`. The `string` method is used by default.
<br />

Importing:

```javascript
// CommonJS Import
const { generateApiKey } = require('generate-api-key');
// OR
const generateApiKey = require('generate-api-key').default;

// ES6 Import
import { generateApiKey } from 'generate-api-key';
// OR
import generateApiKey from 'generate-api-key';
```

Example:

```javascript
const generateApiKey = require('generate-api-key');
import generateApiKey from 'generate-api-key';

// Generate the API key.
generateApiKey(); // ⇨ 'q_EaTiX+xbBXLyO05.+zDXjI+Qi_X0v'
Expand Down Expand Up @@ -95,7 +109,7 @@ Creates an API key/access token using random string generation.
Examples:

```javascript
const generateApiKey = require('generate-api-key');
import generateApiKey from 'generate-api-key';

// Generate the API key. The 'string' method is used by default.
generateApiKey(); // ⇨ 'q_EaTiX+xbBXLyO05.+zDXjI+Qi_X0v'
Expand Down Expand Up @@ -147,7 +161,7 @@ Creates an API key/access token using random bytes.
Examples:

```javascript
const generateApiKey = require('generate-api-key');
import generateApiKey from 'generate-api-key';

// Provide the generation method.
generateApiKey({ method: 'bytes' }); // ⇨ '6f31bfc3717d63e7bd21'
Expand Down Expand Up @@ -188,7 +202,7 @@ Creates an API key/access token using a random UUID and converting it into a [Do
Examples:

```javascript
const generateApiKey = require('generate-api-key');
import generateApiKey from 'generate-api-key';

// Provide the generation method.
generateApiKey({ method: 'base32' }); // ⇨ '2NOLH5I-43EEK7A-R6YRK3I-BRCIQNQ'
Expand Down Expand Up @@ -225,7 +239,7 @@ Creates an API key using Base62 encoding.
Examples:

```javascript
const generateApiKey = require('generate-api-key');
import generateApiKey from 'generate-api-key';

// Provide the generation method.
generateApiKey({ method: 'base62' }); // ⇨ '2AEmXhHtNJkIAqL1S3So6G'
Expand Down Expand Up @@ -260,7 +274,7 @@ Creates an API key/access token using random UUID Version 4 generation.
Examples:

```javascript
const generateApiKey = require('generate-api-key');
import generateApiKey from 'generate-api-key';

// Provide the generation method.
generateApiKey({ method: 'uuidv4' }); // ⇨ 'c40c974f-307e-490e-8d4e-0c8f31f21df3'
Expand Down Expand Up @@ -300,7 +314,7 @@ Creates an API key/access token using random UUID Version 5 generation.
Examples:

```javascript
const generateApiKey = require('generate-api-key');
import generateApiKey from 'generate-api-key';

// Provide the generation method with the name and namespace.
generateApiKey({
Expand Down
2 changes: 1 addition & 1 deletion dist/generate_api_key.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/generate_api_key.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { generateApiKey } from './generate_api_key';
export { generateApiKey, default } from './generate_api_key';
export * from './types';
//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion dist/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/generate_api_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const getUuidV4ApiKey = (options: UuidV4GenerationOptions): string => {

// Check if we should remove dashes.
return (!options.dashes) ? apiKey.replace(/-/g, '') : apiKey;
}
};

/**
* Creates an API key using random UUID Version 5 generation.
Expand Down Expand Up @@ -230,7 +230,7 @@ const getUuidV5ApiKey = (options: UuidV5GenerationOptions): string => {

// Check if we should remove dashes.
return (!options.dashes) ? apiKey.replace(/-/g, '') : apiKey;
}
};

/**
* Generates a simple API key or a batch of API keys based on
Expand Down Expand Up @@ -287,6 +287,6 @@ export const generateApiKey = (options: GenerationOptions = {}): ApiKeyResults =
// Add a prefix if necessary.
return (options.prefix) ? `${options.prefix}.${apiKey}` : apiKey;
}
}
};

export default generateApiKey;
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { generateApiKey } from './generate_api_key';
export { generateApiKey, default } from './generate_api_key';
export * from './types';
11 changes: 11 additions & 0 deletions test/generate_api_key.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,15 @@ describe('generateApiKey', () => {
batch: [],
})).to.throw(TypeError, `The 'batch' option must be a natural number > 0.`);
});

context(`should import 'generateApiKey' as a default import`, () => {
const generateApiKeyDefault = shouldTestBuild
? require('../dist/index').default
: require('../src').default;

// Create the API key.
const apiKey = generateApiKeyDefault();

expect(apiKey).to.be.a('string');
});
});
Loading

0 comments on commit 3db8c58

Please sign in to comment.