Giter VIP home page Giter VIP logo

polish.js's Introduction

Polish.js (the verb, not the language) Making JavaScript better

##Install (note, Polish.js overrides default behavior) ####node.js

npm install polish
require('polish')

####browser

//browser (1.45 KB minified & gzipped)
<script src='polish.js'></script>

##Features ####Array operations

list = [1,2,3,4,5]
list.pop(1) == 2 //list == [1,3,4,5]    pops index
list.remove(2) //list == [1,3,4,5]      removes element
list.insert(2,5) //list == [1,2,5,3,4,5]

####Use Math min/max with lists

Math.min([1,2,3]) == 1
Math.max([1,2,3]) == 3

####Randomness functions

Math.randInt(100) // random int from 0,100 inclusive
[1,2,3].choice() //random object from list
"abc".choice() //random letter from string
[1,2,3].shuffle() //shuffles array in place
"abc".shuffle() //returns new shuffled string

####global functions

range(1,4) == [1,2,3]
range(6,1,-2) == [6,4,2]
zip([[1,2],[3,4],[5,6]]) == [[1,3,5],[2,4,6]]

####Python list/string selectors

list = [1,2,3,4,5]
str = "abcdef"

list.g('-1') == 5
str.g('1:') == "bcdef"
list.g(':2') == [1,2]
str.g('1:3') == "bc"
str.g('-3:-1') == "de"
list.g('::-1') == [5,4,3,2,1]
str.g('3:1:-1') == "dc"

//special -1 selector
list[-1] == 5

####Itertools

Polish.combinations([1,2,3],2) == [[1,2],[1,3],[2,3]]
Polish.combinationsReplace("abc",2) == [['a','a'],['a','b'], ... , ['c','c']]
Polish.permutations([1,2]) == [[1,2],[2,1]]

####Math functions

Math.sum([1,2,3]) == 6
Math.factorial(10) == 3628800
Math.isPrime(23) == true
Math.leastFactor(25) == 5

####Strings

"abc".reverse() == "cba"

Polish.strings
{
    letters: 'abcdefghijklmnopqrstuvwxyz',
    letters_all: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
    digits: '0123456789'
}

####extra

//stringifies and then parses
Polish.clone

###note about modifications: This library has been injected into unit tests for jQuery, backbone, and bootstrap and has not caused any issues ###License: BSD

polish.js's People

Contributors

zolmeister avatar

Stargazers

 avatar Elsa Balderrama avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.