Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
node-js-utilities
Advanced tools
Node.js module exposing some of the basic utils that helps in basic development
Node.js module exposing some of the basic utils that helps in basic development which I came across during development
Author: Gaurav Joshi
const Utils = require('node-utils');
beautifyDate(date, [format, seperator])
beautifyMoney(amount, [currency, raw])
beautifyNumber(number, [decPlaces])
containsWord(string, word)
getDaysDiff(date)
getPathFromUrl(url)
getQueryParamByName(param, url)
getQueryString(url)
getRandomNumber(min, max)
getRandomString(len, charStr)
isUrlValid(url)
startsWith(string, searchString, [position])
stripHtml(html, [all])
beautifyDate(date, [format, seperator])
Generates a decorated date object where:
date
- date.format
- optional format. Available formats are yyyy, mm, yyyy-mm-dd, yyyy-mm-dd h:i, mm-dd-yyyy hh:ss .seperator
- optional Date sepeartor default "-".Utils.beautifyDate('01/16/2016', 'YYYY');
Returns following result:
2017
beautifyNumber(number, [decPlaces])
Generates a decorated Number where:
number
- number.decPlaces
- optional format. Decimal place to round of number .Utils.beautifyNumber(1050000, 2);
Returns following result:
1.05M
beautifyMoney(amount, [currency, raw])
Generates a decorated amount where:
amount
- amount.currency
- optional currency. Available currency format USD,EUR,CRC,GBP,ILS,INR,JPY,KRW,NGN,PHP,PLN,PYG,THB,UAH,VND. Default USDraw
- optional raw. {boolean}Utils.beautifyMoney(1545, 'GBP')
Returns following result:
£1.55K
getDaysDiff(date)
Returns days diff from current date
date
- date.Utils.getDaysDiff('01/01/2017')
Returns following result:
16
stripHtml(html, [all])
Strips HTML content from HTML string. (Returns a promise)
html
- HTML string.all
- Boolean If true strips all HTML content otherwise strips only script tag and its content Utils.stripHtml('<script>alert(1);</script><p>HI GAURAV JOSHI</p><script>alert(1);</script>', true)
.then( str => {
console.log(str);
});
Returns following result:
HI GAURAV JOSHI
containsWord(string, word)
Checks word exists in the string and return true or false accordingly. (*NOTE: check existence of complete word not sub string)
string
- string - string in which to checkword
- word - word to check Utils.containsWord('Hi I am a MEAN stack developer', 'MEAN');
AND
Utils.containsWord('Hi I am a MEAN stack developer', 'velop');
Returns following result:
true
AND
false
getRandomNumber(min, max)
Returns random number between passed range
min
- number - min range default 0max
- number - max range default 1 Utils.getRandomNumber(1, 5);
Returns number
isUrlValid(url)
Returns random number between passed range
url
- string - URL string Utils.isUrlValid('https://☺.damowmow.com/');
Returns boolean
true
getPathFromUrl(url)
Returns path from url skipping query parameters
url
- string - URL string Utils.getPathFromUrl('https://☺.damowmow.com?a=3');
Returns string
https://☺.damowmow.com
getQueryString(url)
Returns query string parameters as an javascript oblect
url
- string - URL string Utils.getQueryString('https://☺.damowmow.com?a=3&b=4');
Returns object
{"a": 3, "b": 4}
getQueryParamByName(param, url)
Returns query string values
param
- string - Param nameurl
- string - URL string Utils.getQueryParamByName('a', 'https://☺.damowmow.com?a=3&b=4');
Returns value or null
3
startsWith(string, searchString, [position])
Determines whether the beginning of searchString instance matches the specified string when compared using the position.
string
- string - The string from compare.searchString
- string - The string to compare.position
- number - position Utils.startsWith('Hello MEAN developers', 'EAN', 7);
Returns boolean
true
getRandomString(len, charStr)
Returns random string of passed length
len
- number - length of random string default 4charStr
- string - charcters list to create random string default aplha numeric Utils.getRandomString(4);
Returns string
FAQs
Node.js module exposing some of the basic utils that helps in basic development
We found that node-js-utilities 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.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.