A JavaScript Utility Library
(the verb, not the language)
Install (note, Polish.js overrides default behavior)
node.js
npm install polish
browser
<!-- browser (1.45 KB minified & gzipped) -->
Features
Array operations
list = 12345list == 2 // list == [1,3,4,5] pops element at indexlist // list == [1,3,4,5] removes element by valuelist // list == [1,2,5,3,4,5]
Use Math min/max with lists
Math == 1Math == 3
Randomness functions
Math // random int from 0,100 inclusive123 //random object from list"abc" //random letter from string123 //shuffles array in place"abc" //returns new shuffled string
Global functions
== 123 == 642
== 135246
Python-inspired list/string selectors
list = 12345str = "abcdef" list == 5str == "bcdef"list == 12str == "bc"str == "de"list == 54321str == "dc" //special -1 selector (picks item from end of list)list-1 == 5
Itertools
Polish == 121323Polish == 'a''a''a''b' ... 'c''c'Polish == 1221
Math functions
Math == 6Math == 3628800Math == trueMath == 5
Strings
"abc" == "cba" Polishstrings letters: 'abcdefghijklmnopqrstuvwxyz' letters_all: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' digits: '0123456789'
Extra
//stringifies and then parsesPolishclone
Compatibility / side-effects:
This library has been injected into unit tests for jQuery, backbone, and bootstrap and has not caused any issues.