natural-sort-js 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +17 -0
- data/Rakefile +15 -0
- data/lib/natural-sort-js.rb +6 -0
- data/lib/natural-sort-js/version.rb +3 -0
- data/lib/tasks/tag.rake +26 -0
- data/vendor/assets/javascripts/0.7.0/naturalsort.js +54 -0
- data/vendor/assets/javascripts/naturalsort.js +54 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MGUyZjE0OTJjNzY0ZTMyNDdiNjZhYWY1ZGNjYTQ5MjJiMzQxNzY2Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZmUzMjNkNzM1MGQzMTU1MWE0M2ZmYzQ4MTI3ZTE5MDIxNTQ3MTg5ZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGEzNTZkYjQ0ZDBiODU0ZTc1NTQwNTViM2MwOTQ3NzNkYzI4YjBjNWNiZGI0
|
10
|
+
ZmY3OGYyNTljMGY3MzNiYjQwNzY5MjM0ZGUwNWEyYWMxMTZlYzg4MjJhNjk0
|
11
|
+
NDU0Y2Y1YWZlMmVhNGYxODY1MmYzY2ViYjc5YmM1ZjI1NzRhNjA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmQzMmVhYzcwNjllMzJmMzQ1MDZkZGQ0NTA2NjhiYjRhOWY2N2VhYzdhZWVh
|
14
|
+
ZDUxNDZmMGNkZWViOTllM2NhYzA5MmU4ZGVlYWIwOWJiMmQ4ZDU4MTA0YjI3
|
15
|
+
Mzg2MDM4N2E2OTcxYTkxYmFkZDY1OTlhNTgwNzc4MTg4MzhhYTY=
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Natural Sort JS
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/natural-sort-js.png)](http://badge.fury.io/rb/natural-sort-js) [![Build Status](https://secure.travis-ci.org/ets-berkeley-edu/natural-sort-js.png)](http://travis-ci.org/ets-berkeley-edu/natural-sort-js) [![Dependency Status](https://gemnasium.com/ets-berkeley-edu/natural-sort-js.png)](https://gemnasium.com/ets-berkeley-edu/natural-sort-js)
|
3
|
+
|
4
|
+
Original natural sort can be found at http://www.overset.com/2008/09/01/javascript-natural-sort-algorithm/
|
5
|
+
|
6
|
+
## Getting Started
|
7
|
+
|
8
|
+
Add the gem to your application Gemfile:
|
9
|
+
|
10
|
+
```
|
11
|
+
gem 'natural-sort-js'
|
12
|
+
```
|
13
|
+
|
14
|
+
## Specifying versions
|
15
|
+
|
16
|
+
- By default, this gem will include the latest stable version of natural sort JS with ``//require natural-sort-js`` in your application.<js/coffee> file.
|
17
|
+
- You can also force specific versions to be loaded with ``//require <VERSION>/natural-sort-js``, assuming the [source files](https://github.com/ets-berkeley-edu/natural-sort-js/tree/master/vendor/assets/javascripts) exist somewhere in the gem.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
|
10
|
+
require 'rake'
|
11
|
+
# http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html
|
12
|
+
require 'net/http'
|
13
|
+
|
14
|
+
Dir.glob('lib/tasks/**/*.rake', &method(:load))
|
15
|
+
|
data/lib/tasks/tag.rake
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
js_dir = 'vendor/assets/javascripts/'
|
2
|
+
|
3
|
+
desc 'Tag the default file versions for asset helpers'
|
4
|
+
task :tag_default do |t|
|
5
|
+
Rake::Task["tag"].invoke
|
6
|
+
end
|
7
|
+
|
8
|
+
task :tag do |t|
|
9
|
+
version = ENV['VERSION']
|
10
|
+
version ||= 'latest'
|
11
|
+
|
12
|
+
puts "Target version: #{version.chomp('/')}"
|
13
|
+
|
14
|
+
Dir.chdir(js_dir) do
|
15
|
+
version_directories = Dir.glob("*").select { |fn| File.directory?(fn) }.sort.reverse
|
16
|
+
if !(version_directories.include? version)
|
17
|
+
puts "WARN: Specified version='#{version}' not found, setting to latest version: '#{version_directories.first}'"
|
18
|
+
version = version_directories.first
|
19
|
+
end
|
20
|
+
new_files = Hash[*Dir.glob("#{version}/*.js").map {|longfn| [longfn.split(version+'/', 2)[1].chomp("-#{version}.js"), longfn]}.flatten]
|
21
|
+
|
22
|
+
new_files.keys.each do |file|
|
23
|
+
FileUtils.cp new_files[file], file.chomp('.js')+'.js', {verbose: true}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
* Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
|
3
|
+
* Author: Jim Palmer (based on chunking idea from Dave Koelle)
|
4
|
+
*/
|
5
|
+
function naturalSort(a, b) {
|
6
|
+
var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi;
|
7
|
+
var sre = /(^[ ]*|[ ]*$)/g;
|
8
|
+
var dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/;
|
9
|
+
var hre = /^0x[0-9a-f]+$/i;
|
10
|
+
var ore = /^0/;
|
11
|
+
var i = function(s) {
|
12
|
+
return naturalSort.insensitive && ('' + s).toLowerCase() || '' + s;
|
13
|
+
};
|
14
|
+
// convert all to strings strip whitespace
|
15
|
+
var x = i(a).replace(sre, '') || '';
|
16
|
+
var y = i(b).replace(sre, '') || '';
|
17
|
+
// chunk/tokenize
|
18
|
+
var xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0');
|
19
|
+
var yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0');
|
20
|
+
// numeric, hex or date detection
|
21
|
+
var xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x));
|
22
|
+
var yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null;
|
23
|
+
var oFxNcL;
|
24
|
+
var oFyNcL;
|
25
|
+
// first try and sort Hex codes or Dates
|
26
|
+
if (yD) {
|
27
|
+
if (xD < yD) {
|
28
|
+
return -1;
|
29
|
+
} else if (xD > yD) {
|
30
|
+
return 1;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
// natural sorting through split numeric strings and default strings
|
34
|
+
for (var cLoc = 0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
|
35
|
+
// find floats not starting with '0', string or 0 if not defined (Clint Priest)
|
36
|
+
oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
|
37
|
+
oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
|
38
|
+
// handle numeric vs string comparison - number < string - (Kyle Adams)
|
39
|
+
if (isNaN(oFxNcL) !== isNaN(oFyNcL)) {
|
40
|
+
return (isNaN(oFxNcL)) ? 1 : -1;
|
41
|
+
} else if (typeof oFxNcL !== typeof oFyNcL) {
|
42
|
+
// rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
|
43
|
+
oFxNcL += '';
|
44
|
+
oFyNcL += '';
|
45
|
+
}
|
46
|
+
if (oFxNcL < oFyNcL) {
|
47
|
+
return -1;
|
48
|
+
}
|
49
|
+
if (oFxNcL > oFyNcL) {
|
50
|
+
return 1;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
return 0;
|
54
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
* Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
|
3
|
+
* Author: Jim Palmer (based on chunking idea from Dave Koelle)
|
4
|
+
*/
|
5
|
+
function naturalSort(a, b) {
|
6
|
+
var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi;
|
7
|
+
var sre = /(^[ ]*|[ ]*$)/g;
|
8
|
+
var dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/;
|
9
|
+
var hre = /^0x[0-9a-f]+$/i;
|
10
|
+
var ore = /^0/;
|
11
|
+
var i = function(s) {
|
12
|
+
return naturalSort.insensitive && ('' + s).toLowerCase() || '' + s;
|
13
|
+
};
|
14
|
+
// convert all to strings strip whitespace
|
15
|
+
var x = i(a).replace(sre, '') || '';
|
16
|
+
var y = i(b).replace(sre, '') || '';
|
17
|
+
// chunk/tokenize
|
18
|
+
var xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0');
|
19
|
+
var yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0');
|
20
|
+
// numeric, hex or date detection
|
21
|
+
var xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x));
|
22
|
+
var yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null;
|
23
|
+
var oFxNcL;
|
24
|
+
var oFyNcL;
|
25
|
+
// first try and sort Hex codes or Dates
|
26
|
+
if (yD) {
|
27
|
+
if (xD < yD) {
|
28
|
+
return -1;
|
29
|
+
} else if (xD > yD) {
|
30
|
+
return 1;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
// natural sorting through split numeric strings and default strings
|
34
|
+
for (var cLoc = 0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
|
35
|
+
// find floats not starting with '0', string or 0 if not defined (Clint Priest)
|
36
|
+
oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
|
37
|
+
oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
|
38
|
+
// handle numeric vs string comparison - number < string - (Kyle Adams)
|
39
|
+
if (isNaN(oFxNcL) !== isNaN(oFyNcL)) {
|
40
|
+
return (isNaN(oFxNcL)) ? 1 : -1;
|
41
|
+
} else if (typeof oFxNcL !== typeof oFyNcL) {
|
42
|
+
// rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
|
43
|
+
oFxNcL += '';
|
44
|
+
oFyNcL += '';
|
45
|
+
}
|
46
|
+
if (oFxNcL < oFyNcL) {
|
47
|
+
return -1;
|
48
|
+
}
|
49
|
+
if (oFxNcL > oFyNcL) {
|
50
|
+
return 1;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
return 0;
|
54
|
+
}
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: natural-sort-js
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Vuerings
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
description: Natural Sort algorithm for Javascript
|
42
|
+
email:
|
43
|
+
- vueringschristian@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/natural-sort-js.rb
|
52
|
+
- lib/natural-sort-js/version.rb
|
53
|
+
- lib/tasks/tag.rake
|
54
|
+
- vendor/assets/javascripts/0.7.0/naturalsort.js
|
55
|
+
- vendor/assets/javascripts/naturalsort.js
|
56
|
+
homepage: http://github.com/ets-berkeley-edu/natural-sort-js
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Naturalsort.js as a gem
|
80
|
+
test_files: []
|