Some useful stuffs packed to here.
- accurateSleep
- chunkify
- chunkifyString
- combinations
- defaultify
- escapeRegex
- execAsync
- fillGaps
- formatDuration
- formatSeconds
- getFileExtension
- getValueType
- hexToRgb
- intToRgba
- isThenable
- makeSureFileExists
- makeSureFileExistsSync
- makeSureFolderExists
- makeSureFolderExistsSync
- mapReplace
- parseDuration
- percent
- randomFloat
- randomInteger
- randomPick
- randomString
- rejectAfter
- rgbaToInt
- rgbToHex
- sleep
- threeDots
- validateShape
- Added
chunkifyString(str, chunkSize, separator?)
. Eg:chunkifyString("Hello, world!", 7, ",")
->["Hello", " world!"]
- Added
formatDuration(ms, formatting?)
. Eg:formatDuration(600000000)
->6 days, 22 hours, 40 minutes
- Added recursive option to
mapReplace(text, map, recursive=true)
. Eg:mapReplace({ test: 1, test2: "hello", deep: { test3: "world" } }, {"hello": "hey", "world": "guy"}, true) => { test: 1, test2: "hey", deep: { test3: "guy" } }
-
combinations(["1","2","3"])
added. Eg: [...combinations(["1","2","3"])] -> [["1"],["2"],["1","2"],["3"],["1","3"],["2","3"],["1","2","3"]]
-
parseDuration(str)
added. Eg: parseDuration("1m30s") -> 90000
- Much better Typescript support.
- Typescript support.
-
mapReplace(text, map)
nowmap
argument supports entry mappings. Eg:[[/a/g, "aaa"], [/b/g, "bbb"]]
;
-
fillGaps(array)
added. Eg: fillGaps([1, 2, 5]) -> [1, 2, 3, 4, 5]
- Fixed
defaultify()
on arrays..
-
validateShape(data, originalData, recursive=true)
added. Validates object shape based on original object types. -
getValueType(value)
added. Eg: getValueType("") -> String, getValueType([]) -> Array
-
defaultify(data, defaultData, recursive=true)
added.
-
execAsync(cmd, cwd?)
added.
-
execAsync(cmd)
added.
-
escapeRegex(str)
added.
-
mapReplace(text, map)
added.- Example:
mapReplace('Hello, world!', {'world': 'Universe'})
- Example:
-
formatSeconds(seconds)
added. Formats seconds to cool-looking string. formatSecond(363) -> '06:03'
-
chunkify(array, chunkSize)
added. Chunks an array into smaller arrays.
-
accurateSleep(milliseconds)
added. For much better for millisecond-level accuracy. But uses more resources.
- Some changes on
defaultify
.
-
makeSureFolderExists(path)
added. -
makeSureFolderExistsSync(path)
added. -
makeSureFileExists(path, content, encoding?)
added. -
makeSureFileExistsSync(path, content, encoding?)
added.
-
defaultify(data, defaultData)
added. (Data is a object)
-
percent(part, total, maxVal?, nanVal?)
added. -
threeDots(text, maxLength)
added.
-
isThenable(any)
added.
- Code cleaned.
- You can now only get only parts you need. (eg.
require('stuffs/lib/randomString')
) - Better readme.
-
randomString(length?, map?)
added.- Some maps added for random string.
randomString.STRING_MAP_HEX
randomString.STRING_MAP_NUMERIC
randomString.STRING_MAP_ALPHABET_LOWER
randomString.STRING_MAP_ALPHABET_UPPER
randomString.STRING_MAP_ALPHANUMERIC
- Some maps added for random string.
-
rejectAfter(ms, reason?)
added.- Throws an error after some time.