Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
randomstring
Advanced tools
The randomstring npm package is a utility for generating random strings. It is useful for creating random identifiers, tokens, passwords, and other strings where randomness is required.
Generate a random string of a specified length
This feature allows you to generate a random string of a specified length. In this example, a random string of 12 characters is generated.
const randomstring = require('randomstring');
const str = randomstring.generate(12);
console.log(str);
Generate a random string with specific character set
This feature allows you to generate a random string using a specific set of characters. In this example, a random string of 8 alphabetic characters is generated.
const randomstring = require('randomstring');
const str = randomstring.generate({
length: 8,
charset: 'alphabetic'
});
console.log(str);
Generate a random string with custom characters
This feature allows you to generate a random string using a custom set of characters. In this example, a random string of 10 characters is generated using the characters 'a', 'b', 'c', '1', '2', and '3'.
const randomstring = require('randomstring');
const str = randomstring.generate({
length: 10,
charset: 'abc123'
});
console.log(str);
The uuid package is used to generate RFC-compliant UUIDs (Universally Unique Identifiers). While it is more focused on generating unique identifiers rather than random strings, it serves a similar purpose in providing unique values.
The crypto-random-string package generates cryptographically strong random strings. It is similar to randomstring but focuses on providing higher security by using the Node.js crypto module.
The nanoid package is a small, secure, URL-friendly, unique string ID generator. It is similar to randomstring but emphasizes security and efficiency, making it suitable for generating unique IDs in web applications.
Library to help you create random strings.
To install randomstring, use npm:
npm install randomstring
var randomstring = require("randomstring");
randomstring.generate();
// >> "XwPp9xazJ0ku5CZnlmgAx2Dld8SHkAeT"
randomstring.generate(7);
// >> "xqm5wXX"
randomstring.generate({
length: 12,
charset: 'alphabetic'
});
// >> "AqoTIzKurxJi"
randomstring.generate({
charset: 'abc'
});
// >> "accbaabbbbcccbccccaacacbbcbbcbbc"
randomstring.generate({
charset: 'abc'
}, cb);
// >> "cb(generatedString) {}"
randomstring.
generate(options, cb)
options
length
- the length of the random string. (default: 32) [OPTIONAL]readable
- exclude poorly readable chars: 0OIl. (default: false) [OPTIONAL]charset
- define the character set for the string. (default: 'alphanumeric') [OPTIONAL]
alphanumeric
- [0-9 a-z A-Z]alphabetic
- [a-z A-Z]numeric
- [0-9]hex
- [0-9 a-f]binary
- [01]octal
- [0-7]custom
- any given characterscapitalization
- define whether the output should be lowercase / uppercase only. (default: null) [OPTIONAL]
lowercase
uppercase
cb
- Optional. If provided uses async version of crypto.randombytes
$ npm install -g randomstring
$ randomstring
> sKCx49VgtHZ59bJOTLcU0Gr06ogUnDJi
$ randomstring 7
> CpMg433
$ randomstring length=24 charset=github readable
> hthbtgiguihgbuttuutubugg
npm install
npm test
node-randomstring is licensed under the MIT license.
FAQs
A module for generating random strings
The npm package randomstring receives a total of 476,110 weekly downloads. As such, randomstring popularity was classified as popular.
We found that randomstring demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.