@anmiles/prototypes v11.1.0
@anmiles/prototypes
Provides prototype extensions for native JS modules
Installation
npm install @anmiles/prototypes
Usage
Number
Number.prototype.case- select russian case of countable entity by countNumber.prototype.pad- add leading or trailing zeros to number to fit specified number of digits
String
String.prototype.toUpperFirstLetter- make first letter uppercaseString.prototype.toLowerFirstLetter- make first letter lowercaseString.prototype.htmlEscape- escape HTML-sensitive stringString.prototype.urlEscape- escape string to make it URL-safeString.prototype.regexEscape- escape regular expressionString.prototype.beautify- unify similar special symbolsString.prototype.toFilename- convert string into a valid filename
Array
Array.prototype.unique- remove duplicates from arrayArray.prototype.equals- compare two arrays item-by-itemArray.prototype.indexFieldOf- indexOf by value of nested keyArray.prototype.sum- sum all values in arrayArray.prototype.sort- sort array by values of nested keys in various directionsArray.prototype.forEachAsync- asynchronous version of Array.prototype.forEachArray.prototype.mapAsync- asynchronous version of Array.prototype.mapArray.prototype.toTuple- cast array to the tuple with fixed amount of elements
Object
Object.fill- fill object with default values generated by keysObject.typedKeys- get typed keys of an objectObject.typedEntries- get typed entries of an object
Error
Error.parse- return an Error object with a message parsed from input of any supported type (or serialized input if not supported)
fs and fs/promises
fs.ensureDir- check and if dir exists and is a directory; optionally create if not existsfs.ensureFile- check if file exists and is a file; optionally create if not existsfs.readJSON- read and parse JSON from filefs.writeJSON- write JSON to filefs.getJSON- get JSON from file with falling back and validationfs.getJSONAsync- asynchronously get JSON from file with asynchronous falling back and asynchronous validationfs.readTSV- read and parse TSV from filefs.writeTSV- write TSV to filefs.joinPath- join two portions of file path using specified or default separator and return the path as typed as possiblefs.recurse- recursively traverse directory for specified depth and apply callbacks for files (with optionally specified extension), directories and linksfs.size- recursively calculates get directory size
Also joinPath and recurse functions are introduced in fs.posix and fs.win32 namespaces.
Path separator is explicitly specified and cannot be directly passed there.
fs.posix.joinPathandfs.posix.recurseuse '/' separator regardless of path.sep in runtimefs.win32.joinPathandfs.win32.recurseuse '\' separator regardless of path.sep in runtime Inspired bypath.posixandpath.win32.
Useful strings for testing purposes:
- string value
-
begin .-'`"~!@#$%^&*?:;,_=+/\|()[]{}<> <>%27²½áßÈіíž©§€₤∑א雨https://A-_/?b[c]&(1)end - query string value
-
begin .-'`"~!@$%^*:;,_=+\|()[]{}<>%27²½áßÈіíž©§€₤∑א雨https://A-_/b[c](1)end - url
-
https://example.com/begin.-'`"~!@#$%^&*?:;,_=+/\|()[]{}<> <>%27²½áßÈіíž©§€₤∑א雨end - email
-
test.-'`~!#$%^&*?_=+/|{} <>%27іž€₤∑א雨@example.com
5 months ago
5 months ago
5 months ago
5 months ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago