Socket
Socket
Sign inDemoInstall

@smakss/random-string

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smakss/random-string - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

24

dist/cjs/index.d.ts

@@ -0,1 +1,25 @@

/**
* Generates a random string based on the given length and set of allowed characters.
*
* @param {Object} [options={}] - The options for generating the random string.
* @param {number} [options.length=Math.ceil(Math.random() * 20)] - The length of the string to generate.
* @param {string} [options.allowedCharacters=DEFAULT_ALLOWED_CHARACTERS] - A string of allowed characters.
* @returns {string} The generated random string.
*
* @example
* // Example 1: Generate a random string with default options
* const randomStr = randomString();
* console.log(randomStr); // Output will be a random string of length between 1 and 20 characters.
*
* @example
* // Example 2: Generate a random string of length 10
* const randomStr10 = randomString({ length: 10 });
* console.log(randomStr10); // Output will be a random string of exactly 10 characters.
*
* @example
* // Example 3: Generate a random string of length 5 with specific allowed characters
* const allowedChars = 'abc123';
* const randomStrCustom = randomString({ length: 5, allowedCharacters: allowedChars });
* console.log(randomStrCustom); // Output will be a random string of exactly 5 characters, with characters only from 'abc123'.
*/
declare function randomString({ length, allowedCharacters }?: {

@@ -2,0 +26,0 @@ length?: number;

@@ -6,2 +6,26 @@ 'use strict';

const DEFAULT_ALLOWED_CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*';
/**
* Generates a random string based on the given length and set of allowed characters.
*
* @param {Object} [options={}] - The options for generating the random string.
* @param {number} [options.length=Math.ceil(Math.random() * 20)] - The length of the string to generate.
* @param {string} [options.allowedCharacters=DEFAULT_ALLOWED_CHARACTERS] - A string of allowed characters.
* @returns {string} The generated random string.
*
* @example
* // Example 1: Generate a random string with default options
* const randomStr = randomString();
* console.log(randomStr); // Output will be a random string of length between 1 and 20 characters.
*
* @example
* // Example 2: Generate a random string of length 10
* const randomStr10 = randomString({ length: 10 });
* console.log(randomStr10); // Output will be a random string of exactly 10 characters.
*
* @example
* // Example 3: Generate a random string of length 5 with specific allowed characters
* const allowedChars = 'abc123';
* const randomStrCustom = randomString({ length: 5, allowedCharacters: allowedChars });
* console.log(randomStrCustom); // Output will be a random string of exactly 5 characters, with characters only from 'abc123'.
*/
function randomString({ length = Math.ceil(Math.random() * 20), allowedCharacters = DEFAULT_ALLOWED_CHARACTERS } = {}) {

@@ -8,0 +32,0 @@ const charactersLength = allowedCharacters.length;

@@ -0,1 +1,25 @@

/**
* Generates a random string based on the given length and set of allowed characters.
*
* @param {Object} [options={}] - The options for generating the random string.
* @param {number} [options.length=Math.ceil(Math.random() * 20)] - The length of the string to generate.
* @param {string} [options.allowedCharacters=DEFAULT_ALLOWED_CHARACTERS] - A string of allowed characters.
* @returns {string} The generated random string.
*
* @example
* // Example 1: Generate a random string with default options
* const randomStr = randomString();
* console.log(randomStr); // Output will be a random string of length between 1 and 20 characters.
*
* @example
* // Example 2: Generate a random string of length 10
* const randomStr10 = randomString({ length: 10 });
* console.log(randomStr10); // Output will be a random string of exactly 10 characters.
*
* @example
* // Example 3: Generate a random string of length 5 with specific allowed characters
* const allowedChars = 'abc123';
* const randomStrCustom = randomString({ length: 5, allowedCharacters: allowedChars });
* console.log(randomStrCustom); // Output will be a random string of exactly 5 characters, with characters only from 'abc123'.
*/
declare function randomString({ length, allowedCharacters }?: {

@@ -2,0 +26,0 @@ length?: number;

const DEFAULT_ALLOWED_CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*';
/**
* Generates a random string based on the given length and set of allowed characters.
*
* @param {Object} [options={}] - The options for generating the random string.
* @param {number} [options.length=Math.ceil(Math.random() * 20)] - The length of the string to generate.
* @param {string} [options.allowedCharacters=DEFAULT_ALLOWED_CHARACTERS] - A string of allowed characters.
* @returns {string} The generated random string.
*
* @example
* // Example 1: Generate a random string with default options
* const randomStr = randomString();
* console.log(randomStr); // Output will be a random string of length between 1 and 20 characters.
*
* @example
* // Example 2: Generate a random string of length 10
* const randomStr10 = randomString({ length: 10 });
* console.log(randomStr10); // Output will be a random string of exactly 10 characters.
*
* @example
* // Example 3: Generate a random string of length 5 with specific allowed characters
* const allowedChars = 'abc123';
* const randomStrCustom = randomString({ length: 5, allowedCharacters: allowedChars });
* console.log(randomStrCustom); // Output will be a random string of exactly 5 characters, with characters only from 'abc123'.
*/
function randomString({ length = Math.ceil(Math.random() * 20), allowedCharacters = DEFAULT_ALLOWED_CHARACTERS } = {}) {

@@ -3,0 +27,0 @@ const charactersLength = allowedCharacters.length;

33

package.json

@@ -6,3 +6,3 @@ {

},
"description": "Generates random dummy string with random length.",
"description": "Effortlessly generate customizable random strings with @smakss/random-string. Ideal for creating dummy strings, custom-length passwords, or unique identifiers. Integrates seamlessly with both CommonJS and ECMAScript modules.",
"devDependencies": {

@@ -31,5 +31,28 @@ "@commitlint/cli": "^18.2.0",

},
"files": ["dist"],
"files": [
"dist"
],
"homepage": "https://github.com/SMAKSS/random-string#readme",
"keywords": ["npm", "yarn", "dummy", "string", "SMAKSS", "random", "CommonJS", "EcmaScript", "Typescript", "random-string"],
"keywords": [
"random-string",
"password-generator",
"string-generator",
"npm",
"yarn",
"typescript",
"ecmascript",
"random-string-utility",
"SMAKSS",
"custom-string",
"string-utility",
"secure-string",
"random-passwords",
"dummy-data",
"dummy-string",
"random-characters",
"string-creation",
"custom-passwords",
"javascript-utility",
"nodejs"
],
"license": "MIT",

@@ -55,3 +78,3 @@ "main": "dist/cjs/index.js",

"types": "lib",
"version": "2.0.0"
}
"version": "2.0.1"
}

2

Readme.md

@@ -30,3 +30,3 @@ # Generate random string

```js
const randomString = require('@smakss/random-string').default;
const randomString = require('@smakss/random-string');
```

@@ -33,0 +33,0 @@

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