
Product
Introducing the Alert Details Page: A Better Way to Explore Alerts
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.
node-powertools
Advanced tools
Site | NPM Module | GitHub Repo
Node Powertools is an NPM module for backend and frontend developers that exposes powerful utilities and tools.
Yes, this module works in both Node and browser environments, including compatibility with Webpack and Browserify!
RegExpInstall with npm if you plan to use Node Powertools in a Node.js project or in the browser.
npm install node-powertools
If you plan to use node-powertools in a browser environment, you will probably need to use Webpack, Browserify, or a similar service to compile it.
const powertools = require('node-powertools');
Install with CDN if you plan to use Node Powertools only in a browser environment.
<script src="https://cdn.jsdelivr.net/npm/node-powertools@latest/dist/index.min.js"></script>
<script type="text/javascript">
var powertools = Powertools(); // The script above exposes the global variable 'Powertools'
</script>
Generate a random number between two numbers min and max. You can use options to supply a sign or randomize the sign as well. If an array is supplied, a random element from the array is returned.
The default options.mode is uniform but you can also supply gaussian which will generate random values on a gaussian bell curve.
powertools.random(0, 100, {mode: 'uniform'}); // Possible output: 69
powertools.random(-100, 100, {mode: 'uniform'}); // Possible output: -69
powertools.random(-100, 100, {mode: 'gaussian'}); // Possible output: -69
powertools.random(['Apple', 'Orange', 'Pear']); // Possible output: Orange (random element)
Transform the input into an array if it is not already.
powertools.arrayify(1); // Output: [1]
powertools.arrayify([1]); // Output: [1]
Asynchronously wait for the specified time in milliseconds.
await powertools.wait(1000); // waits for 1000 ms (1 second)
Asynchronously wait for the specified fn to return true. You can use options to supply a polling interval and timeout in milliseconds. The promise rejects if the timeout is reached.
// Call this function every 100 ms until it returns true or 30000 ms passes
await powertools.poll(function () {
return something === somethingElse;
}, {interval: 100, timeout: 30000});
Add the escape character \ before any character in str that needs to be escaped for a RegExp.
powertools.escape('*'); // Output: \*
powertools.escape('/'); // Output: \/
powertools.escape('\\'); // Output: \\
powertools.escape('.$^'); // Output: \.\$\^
Revive a str into a RegExp. Supports flags. Depending on how you want special characters to be treated, you can use powertools.escape(str) prior to using powertools.regexify(str).
powertools.regexify('/Apple/'); // Output: RegExp /Apple/
powertools.regexify('/Apple/i'); // Output: RegExp /Apple/i
powertools.regexify('Apple'); // Output: Throws error (needs to start and end with /)
powertools.regexify('/Apple/x'); // Output: Throws error (x is not a valid flag)
powertools.regexify('/Ap.le/'); // Output: RegExp /Ap.le/
powertools.regexify(`/${powertools.escape('Ap.le')}/`); // Output: RegExp /Ap\.le/
Convert a date to a timestamp in 3 formats: an ISO string, a UNIX number, or a plain-ol' JS Date (as specified in options).
The first argument date can be a JS Date, a UNIX timestamp number, or a string that will be parsed by the new Date() method.
powertools.timestamp(new Date('2999/12/31'), {output: 'string'}); // Output: "2999-12-31T08:00:00.000Z"
powertools.timestamp(new Date('2999/12/31'), {output: 'unix'}); // Output: 32503622400
powertools.timestamp(new Date('2999/12/31'), {output: 'date'}); // Output: Tue Dec 31 2999 00:00:00 GMT-0800 (Pacific Standard Time)
powertools.timestamp(32503622400, {output: 'string'}); // Output: "2999-12-31T08:00:00.000Z"
powertools.timestamp(32503622400, {output: 'unix'}); // Output: 32503622400
powertools.timestamp(32503622400, {output: 'date'}); // Output: Tue Dec 31 2999 00:00:00 GMT-0800 (Pacific Standard Time)
Intelligently converts a value to a type how JavaScript should. The acceptable types are string, number, boolean, array.
powertools.force(undefined, 'string'); // Output: ''
powertools.force('true', 'boolean'); // Output: true
powertools.force('false', 'boolean'); // Output: false
powertools.force('0', 'boolean'); // Output: false
powertools.force('1,2,3', 'array'); // Output: ['1', '2', '3']
powertools.force('1,2,3', 'array', {force: 'number'}); // Output: [1, 2, 3]
If you are still having difficulty, we would love for you to post a question to the Node Powertools issues page. It is much easier to answer questions that include your code and relevant files! So if you can provide them, we'd be extremely grateful (and more likely to help you find the answer!)
Somiibo: A Social Media Bot with an open-source module library.
JekyllUp: A website devoted to sharing the best Jekyll themes.
Slapform: A backend processor for your HTML forms on static sites.
Proxifly: A backend processor for your HTML forms on static sites.
SoundGrail Music App: A resource for producers, musicians, and DJs.
Hammock Report: An API for exploring and listing backyard products.
Ask us to have your project listed! :)
FAQs
Powerful assistive functions for Node and Browser environments.
The npm package node-powertools receives a total of 513 weekly downloads. As such, node-powertools popularity was classified as not popular.
We found that node-powertools demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.

Research
Malicious PyPI package sympy-dev targets SymPy users, a Python symbolic math library with 85 million monthly downloads.