diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/alphanum-sort | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/alphanum-sort')
| -rw-r--r-- | node_modules/alphanum-sort/LICENSE | 22 | ||||
| -rw-r--r-- | node_modules/alphanum-sort/README.md | 45 | ||||
| -rw-r--r-- | node_modules/alphanum-sort/lib/compare.js | 183 | ||||
| -rw-r--r-- | node_modules/alphanum-sort/lib/index.js | 34 | ||||
| -rw-r--r-- | node_modules/alphanum-sort/package.json | 35 |
5 files changed, 319 insertions, 0 deletions
diff --git a/node_modules/alphanum-sort/LICENSE b/node_modules/alphanum-sort/LICENSE new file mode 100644 index 00000000..f37fd710 --- /dev/null +++ b/node_modules/alphanum-sort/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) Bogdan Chadkin <trysound@yandex.ru>
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/alphanum-sort/README.md b/node_modules/alphanum-sort/README.md new file mode 100644 index 00000000..506be21d --- /dev/null +++ b/node_modules/alphanum-sort/README.md @@ -0,0 +1,45 @@ +# alphanum-sort
+[](https://travis-ci.org/TrySound/alphanum-sort)
+
+> Alphanumeric sorting algorithm
+
+## Install
+
+With [npm](https://npmjs.org/package/alphanum-sort) do:
+
+```
+npm i alphanum-sort -S
+```
+
+## Example
+
+```js
+var sort = require('alphanum-sort');
+
+var result = sort(['item20', 'item19', 'item1', 'item10', 'item2']);
+// ['item1', 'item2', 'item10', 'item19', 'item20']
+```
+
+## API
+
+### alphanumSort(array, options)
+
+#### options
+
+##### insensitive
+
+Type: `Boolean`
+Default: `false`
+
+Compares items case insensitively
+
+##### sign
+
+Type: `Boolean`
+Default: `false`
+
+Allows `+` and `-` characters before numbers
+
+## License
+
+MIT © [Bogdan Chadkin](https://github.com/trysound)
diff --git a/node_modules/alphanum-sort/lib/compare.js b/node_modules/alphanum-sort/lib/compare.js new file mode 100644 index 00000000..91886772 --- /dev/null +++ b/node_modules/alphanum-sort/lib/compare.js @@ -0,0 +1,183 @@ +var zero = '0'.charCodeAt(0);
+var plus = '+'.charCodeAt(0);
+var minus = '-'.charCodeAt(0);
+
+function isWhitespace(code) {
+ return code <= 32;
+}
+
+function isDigit(code) {
+ return 48 <= code && code <= 57;
+}
+
+function isSign(code) {
+ return code === minus || code === plus;
+}
+
+module.exports = function (opts, a, b) {
+ var checkSign = opts.sign;
+ var ia = 0;
+ var ib = 0;
+ var ma = a.length;
+ var mb = b.length;
+ var ca, cb; // character code
+ var za, zb; // leading zero count
+ var na, nb; // number length
+ var sa, sb; // number sign
+ var ta, tb; // temporary
+ var bias;
+
+ while (ia < ma && ib < mb) {
+ ca = a.charCodeAt(ia);
+ cb = b.charCodeAt(ib);
+ za = zb = 0;
+ na = nb = 0;
+ sa = sb = true;
+ bias = 0;
+
+ // skip over leading spaces
+ while (isWhitespace(ca)) {
+ ia += 1;
+ ca = a.charCodeAt(ia);
+ }
+ while (isWhitespace(cb)) {
+ ib += 1;
+ cb = b.charCodeAt(ib);
+ }
+
+ // skip and save sign
+ if (checkSign) {
+ ta = a.charCodeAt(ia + 1);
+ if (isSign(ca) && isDigit(ta)) {
+ if (ca === minus) {
+ sa = false;
+ }
+ ia += 1;
+ ca = ta;
+ }
+ tb = b.charCodeAt(ib + 1);
+ if (isSign(cb) && isDigit(tb)) {
+ if (cb === minus) {
+ sb = false;
+ }
+ ib += 1;
+ cb = tb;
+ }
+ }
+
+ // compare digits with other symbols
+ if (isDigit(ca) && !isDigit(cb)) {
+ return -1;
+ }
+ if (!isDigit(ca) && isDigit(cb)) {
+ return 1;
+ }
+
+ // compare negative and positive
+ if (!sa && sb) {
+ return -1;
+ }
+ if (sa && !sb) {
+ return 1;
+ }
+
+ // count leading zeros
+ while (ca === zero) {
+ za += 1;
+ ia += 1;
+ ca = a.charCodeAt(ia);
+ }
+ while (cb === zero) {
+ zb += 1;
+ ib += 1;
+ cb = b.charCodeAt(ib);
+ }
+
+ // count numbers
+ while (isDigit(ca) || isDigit(cb)) {
+ if (isDigit(ca) && isDigit(cb) && bias === 0) {
+ if (sa) {
+ if (ca < cb) {
+ bias = -1;
+ } else if (ca > cb) {
+ bias = 1;
+ }
+ } else {
+ if (ca > cb) {
+ bias = -1;
+ } else if (ca < cb) {
+ bias = 1;
+ }
+ }
+ }
+ if (isDigit(ca)) {
+ ia += 1;
+ na += 1;
+ ca = a.charCodeAt(ia);
+ }
+ if (isDigit(cb)) {
+ ib += 1;
+ nb += 1;
+ cb = b.charCodeAt(ib);
+ }
+ }
+
+ // compare number length
+ if (sa) {
+ if (na < nb) {
+ return -1;
+ }
+ if (na > nb) {
+ return 1;
+ }
+ } else {
+ if (na > nb) {
+ return -1;
+ }
+ if (na < nb) {
+ return 1;
+ }
+ }
+
+ // compare numbers
+ if (bias) {
+ return bias;
+ }
+
+ // compare leading zeros
+ if (sa) {
+ if (za > zb) {
+ return -1;
+ }
+ if (za < zb) {
+ return 1;
+ }
+ } else {
+ if (za < zb) {
+ return -1;
+ }
+ if (za > zb) {
+ return 1;
+ }
+ }
+
+ // compare ascii codes
+ if (ca < cb) {
+ return -1;
+ }
+ if (ca > cb) {
+ return 1;
+ }
+
+ ia += 1;
+ ib += 1;
+ }
+
+ // compare length
+ if (ma < mb) {
+ return -1;
+ }
+ if (ma > mb) {
+ return 1;
+ }
+};
diff --git a/node_modules/alphanum-sort/lib/index.js b/node_modules/alphanum-sort/lib/index.js new file mode 100644 index 00000000..9df38f02 --- /dev/null +++ b/node_modules/alphanum-sort/lib/index.js @@ -0,0 +1,34 @@ +var compare = require('./compare'); + +function mediator(a, b) { + return compare(this, a.converted, b.converted); +} + +module.exports = function (array, opts) { + if (!Array.isArray(array) || array.length < 2) { + return array; + } + if (typeof opts !== 'object') { + opts = {}; + } + opts.sign = !!opts.sign; + var insensitive = !!opts.insensitive; + var result = Array(array.length); + var i, max, value; + + for (i = 0, max = array.length; i < max; i += 1) { + value = String(array[i]); + result[i] = { + value: array[i], + converted: insensitive ? value.toLowerCase() : value + }; + } + + result.sort(mediator.bind(opts)); + + for (i = result.length - 1; ~i; i -= 1) { + result[i] = result[i].value; + } + + return result; +}; diff --git a/node_modules/alphanum-sort/package.json b/node_modules/alphanum-sort/package.json new file mode 100644 index 00000000..ee92678d --- /dev/null +++ b/node_modules/alphanum-sort/package.json @@ -0,0 +1,35 @@ +{ + "name": "alphanum-sort", + "version": "1.0.2", + "description": "Alphanumeric sorting algorithm", + "main": "lib/index.js", + "files": [ + "lib" + ], + "devDependencies": { + "eslint": "^1.5.1", + "javascript-natural-sort": "^0.7.1", + "tap-spec": "^4.1.0", + "tape": "^4.2.0" + }, + "scripts": { + "test": "eslint lib test.js && tape test.js | tap-spec" + }, + "author": "Bogdan Chadkin <trysound@yandex.ru>", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/TrySound/alphanum-sort.git" + }, + "bugs": { + "url": "https://github.com/TrySound/alphanum-sort/issues" + }, + "homepage": "https://github.com/TrySound/alphanum-sort", + "keywords": [ + "sort", + "alphanum", + "alphanumeric", + "natural", + "human" + ] +} |
