Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

generate-api-key

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generate-api-key - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

28

dist/generate_api_key.js

@@ -22,3 +22,3 @@ "use strict";

const getCryptoApiKey = (options) => {
let totalBytes;
var _a;
let apiKey;

@@ -32,22 +32,16 @@ // Get the options.

const chance = new chance_1.default();
if (options.length) {
totalBytes = Math.ceil(options.length / 2);
}
else {
// Get a random number.
const numVal = chance.natural({ min: options.min, max: options.max });
// Set the total bytes.
totalBytes = Math.ceil(numVal / 2);
}
// Determine the length for the key.
const length = (_a = options.length) !== null && _a !== void 0 ? _a : chance.natural({
min: options.min,
max: options.max
});
// Set the total bytes.
const totalBytes = Math.ceil(length / 2);
// Generate the API key.
apiKey = (0, crypto_1.randomBytes)(totalBytes).toString('hex');
// Check the key length.
if (options.length && (apiKey.length > options.length)) {
const endIndex = apiKey.length - (apiKey.length - options.length);
if (apiKey.length > length) {
const endIndex = apiKey.length - (apiKey.length - length);
apiKey = apiKey.slice(0, endIndex);
}
else if (apiKey.length > options.max) {
const endIndex = apiKey.length - (apiKey.length - options.max);
apiKey = apiKey.slice(0, endIndex);
}
return apiKey;

@@ -74,3 +68,3 @@ };

min: options.min,
max: options.min
max: options.max
});

@@ -77,0 +71,0 @@ // Generate the string.

{
"name": "generate-api-key",
"description": "A library for generating random API key/access tokens",
"version": "1.0.1",
"version": "1.0.2",
"main": "./dist/index.js",

@@ -6,0 +6,0 @@ "types": "./dist/index.d.ts",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc