Jextend

常用的一些javascript函数总结

Status

代码 已经打包发布到 RubyGems.

image

Installation

Add this line to your application's Gemfile:

gem 'jextend'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jextend

Write this in your application.js

//=require jextend

Usage

Array

[2,3,5].contains(3);
//=>true
[2,3,5].contains(6);
//=>false

Date

new Date().format('yyyy-MM-dd');
//=>"2016-04-20"

Math

Math.n_pow(2,3);
//=>8_
Math.decimal_point('3.3333',2);
//=>3.33_

String

"Good {0} everyone.How do {1} do?".format('morning','you');
//=> "Good morning everyone.How do you do?"

String.random(32);
//=>"t7m5dzu3zn2jxb34qykjkrifjeo77rj1"

String.random(10,true);
//=>"f0jz19hgER"

window.location.params

//current_url: http://localhost:3000/?start_date=2015-12-06&type=newer_
window.location.params()
//=>{start_date:'2015-12-06',type:'newer'}

Contributing

  1. Fork it ( https://github.com/[my-github-username]/jextend/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request