This project is now archived, I will not update / maintain it anymore
Javascript utilities belt for very specific tasks.
main goal(s):
- console log wrapper for colored log messages
- utilities belt: javascript collection of useful functions that are useful for specific situations, so a lot more specific than underscore
- should work in the browser as well in nodejs
@TODO
install the latest nodejs (if you haven't already) nodejs
install or update to the latest git version git scm downloads (During installation at the step "choosing the default editor used by Git", if like me you are using visual studio code you might want to chose the new option "use visual studio code as Git's default editor") (also if like me you are on windows, at the step "adjusting your PATH environment", ensure the second radio button option is selected "git from the line and also from 3rd-party software" to ensure git is added to the windows PATH, which will allow you to use git with any command line tool like windows powershell for example)
git clone this repository if you haven't already
open your favorite command line tool and go to the root directory of this repository
update npm to latest version
npm install npm@latest -g
install the dependencies
npm i
to lint the typescript files
npm run lint
run the tests
npm run test
to build the distributions (es6 module (esm.js) and the UMD version)
npm run build
in devlopment you can use watch to rebuild every time you edit a typescript file
npm run watch
you can also use watch for the test suite
npm run watch:test
Bug reports, tests, fixes, new features and all kind of comments / feedback are welcome 😃 Submit a feature request or bug issue
I used the jest testing framework
I added the jest typescript types and the ts-jest package
installed dependencies:
npm install --save-dev jest @types/jest ts-jest
command to create a basic jest.config.js file:
npx ts-jest config:init yarn ts-jest config:init
If you use VSCode, consider using the vscode jest extension
Besides reading the official documentation, you can check out this quick introduction to jest blog post
Colored console log messages for the browser and / or nodejs
utilities.log('foo', 'bar', 'fontColor:red', 'backgroundColor:blue');
- red
- green
- yellow
- blue
- magenta
- cyan
- white
- black
If you are on mobile device and wan't to show the messages in a floating div over the page then set logSpecial to true
utilities.logSpecial = true
If want every message to logged in file, then enable logSpecial (currently only winston is supported)
utilities.logSpecial = true
utilities.logSpecial = true
utilities.logVerbose = false
removes html elements from a sting (and their content) from strings set second parameter "removeTextBetweenTags" to false to keep the text between the opening and closing html tag
returns a universally unique identifier
filters a string removes everything that is a not an alpha or numeric character and also optionally the characters that got specified as second argument
decode uri
encode uri
remove an something at an unknown index from an array
capitalise first letter of a string
get url parameters
does a string contain another string
get the index of a substring in a string with optional nth time it occurs
does the script run on the server
does the script run in a client
first parameter is a string and second parameter an object where the keys are the placeholder that need to get replaced and the value is the replacement (replacement can be a string or number)
Input are two numbers, output is a random number that is between or equal the two input numbers
Input is a sequence (an array) of items and the output one random item of the input