@shelf/fast-natural-order-by
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -1,3 +0,1 @@ | ||
import orderBy from './orderBy'; | ||
import compare from './compare'; | ||
export { orderBy, compare }; | ||
export { orderBy, compare } from 'natural-orderby'; |
@@ -1,1 +0,2 @@ | ||
!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var n=r();for(var t in n)("object"==typeof exports?exports:e)[t]=n[t]}}("undefined"!=typeof self?self:this,(()=>(()=>{"use strict";var e={d:(r,n)=>{for(var t in n)e.o(n,t)&&!e.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:n[t]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{compare:()=>F,orderBy:()=>w});const n=(e,r)=>e<r?-1:e>r?1:0,t=/(^0x[\da-fA-F]+$|^([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?(?!\.\d+)(?=\D|\s|$))|\d+)/g,o=/^\s+|\s+$/g,i=/\s+/g,s=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/,a=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[/-]\d{1,4}[/-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,u=/^0+[1-9]{1}[0-9]*$/,c=/[^\x00-\x80]/,d=(e,r)=>{const n=e.localeCompare(r);return n?n/Math.abs(n):0},l=(e,r)=>e<r?-1:e>r?1:0,f=(e,r)=>e.value===r.value?0:void 0!==e.parsedNumber&&void 0!==r.parsedNumber?n(e.parsedNumber,r.parsedNumber):e.chunks&&r.chunks?((e,r)=>{const t=e.length,o=r.length,i=Math.min(t,o);for(let t=0;t<i;t++){const o=e[t],i=r[t];if(o.normalizedString!==i.normalizedString){if(""===o.normalizedString!=(""===i.normalizedString))return""===o.normalizedString?-1:1;if(void 0!==o.parsedNumber&&void 0!==i.parsedNumber){const e=n(o.parsedNumber,i.parsedNumber);return 0===e?l(o.normalizedString,i.normalizedString):e}return void 0!==o.parsedNumber||void 0!==i.parsedNumber?void 0!==o.parsedNumber?-1:1:c.test(o.normalizedString+i.normalizedString)&&o.normalizedString.localeCompare?d(o.normalizedString,i.normalizedString):l(o.normalizedString,i.normalizedString)}}return t>i||o>i?t<=i?-1:1:0})(e.chunks,r.chunks):((e,r)=>(e.chunks?!r.chunks:r.chunks)?e.chunks?-1:1:(e.isNaN?!r.isNaN:r.isNaN)?e.isNaN?-1:1:(e.isSymbol?!r.isSymbol:r.isSymbol)?e.isSymbol?-1:1:(e.isObject?!r.isObject:r.isObject)?e.isObject?-1:1:(e.isArray?!r.isArray:r.isArray)?e.isArray?-1:1:(e.isFunction?!r.isFunction:r.isFunction)?e.isFunction?-1:1:(e.isNull?!r.isNull:r.isNull)?e.isNull?-1:1:0)(e,r),m=e=>"function"==typeof e?e:r=>{if(Array.isArray(r)){const n=Number(e);if(Number.isInteger(n))return r[n]}else if(r&&"object"==typeof r&&"function"!=typeof e)return r[e];return r},p=e=>{if(0!==e.length){const r=Number(e);if(!Number.isNaN(r))return r}},y=e=>{const r=p(e);return void 0!==r?r:(e=>{try{const r=Date.parse(e);return!Number.isNaN(r)&&a.test(e)?r:void 0}catch{return}})(e)},b=e=>e.replace(i," ").replace(o,""),N=(e,r,n)=>{if(s.test(e)&&(!u.test(e)||0===r||"."!==n[r-1]))return p(e)||0},g=(e,r,n)=>({parsedNumber:N(e,r,n),normalizedString:b(e)}),S=function(e){return(e=>e.replace(t,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"))(e).map(g)},v=function(e){return"function"==typeof e},h=e=>Number.isNaN(e)||e instanceof Number&&Number.isNaN(e.valueOf()),A=e=>null===e,j=e=>!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof Number||e instanceof String||e instanceof Boolean||e instanceof Date),z=e=>"symbol"==typeof e,x=e=>void 0===e,O=e=>{if("string"==typeof e||e instanceof String||("number"==typeof e||e instanceof Number)&&!h(e)||"boolean"==typeof e||e instanceof Boolean||e instanceof Date){const r=(e=>"boolean"==typeof e||e instanceof Boolean?Number(e).toString():"number"==typeof e||e instanceof Number?e.toString():e instanceof Date?e.getTime().toString():"string"==typeof e||e instanceof String?e.toLowerCase().replace(o,""):"")(e),n=y(r);return{parsedNumber:n,chunks:S(n?`${n}`:r),value:e}}return{isArray:Array.isArray(e),isFunction:v(e),isNaN:h(e),isNull:A(e),isObject:j(e),isSymbol:z(e),isUndefined:x(e),value:e}},k=(e,r,n)=>{const t=r.length?r.map(m):[e=>e],o=e.map(((e,r)=>({index:r,values:t.map((r=>r(e))).map(O)})));return o.sort(((e,r)=>((e,r,n)=>{const{index:t,values:o}=e,{index:i,values:s}=r,{length:a}=o,u=n.length;for(let e=0;e<a;e++){const r=e<u?n[e]:null;if(r&&"function"==typeof r){const n=r(o[e].value,s[e].value);if(n)return n}else{const n=f(o[e],s[e]);if(n)return n*("desc"===r?-1:1)}}return t-i})(e,r,n))),o.map((r=>((e,r)=>e[r])(e,r.index)))},w=function(e,r,n){if(!e||!Array.isArray(e))return[];const t=(e=>{if(!e)return[];const r=Array.isArray(e)?[...e]:[e];return r.some((e=>"string"!=typeof e&&"number"!=typeof e&&"function"!=typeof e))?[]:r})(r),o=(e=>{if(!e)return[];const r=Array.isArray(e)?[...e]:[e];return r.some((e=>"asc"!==e&&"desc"!==e&&"function"!=typeof e))?[]:r})(n);return k(e,t,o)},$=e=>"string"==typeof e&&("asc"===e||"desc"===e),F=function(e){return function(e){return(r,n)=>{const t=O(r),o=O(n);return f(t,o)*("desc"===e.order?-1:1)}}((e=>{let r="asc";return"string"==typeof e&&$(e)?r=e:e&&"object"==typeof e&&e.order&&$(e.order)&&({order:r}=e),{order:r}})(e))};return r})())); | ||
// eslint-disable-next-line no-restricted-imports | ||
export { orderBy, compare } from 'natural-orderby'; |
{ | ||
"name": "@shelf/fast-natural-order-by", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Lightweight and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc. 150,000x faster fork of natural-orderby for longer strings", | ||
@@ -11,3 +11,6 @@ "license": "MIT", | ||
}, | ||
"main": "lib", | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": "./lib/index.js", | ||
"module": "./lib/index.js", | ||
"types": "lib/index.d.ts", | ||
@@ -18,11 +21,10 @@ "files": [ | ||
"scripts": { | ||
"benchmark": "yarn build && babel benchmark.ts | node", | ||
"build": "rm -rf lib/ && yarn build:types && yarn build:webpack", | ||
"build:types": "tsc -p tsconfig.types.json", | ||
"build:webpack": "NODE_ENV=production webpack", | ||
"benchmark": "yarn build && npx tsx benchmark.ts", | ||
"build": "rm -rf lib/ && tsc", | ||
"coverage": "yarn test --coverage", | ||
"lint": "yarn lint:ci --fix", | ||
"lint:ci": "eslint . --ext .js,.ts,.json", | ||
"lint:size": "size-limit", | ||
"prepack": "yarn build", | ||
"test": "TZ=UTC jest src", | ||
"test": "NODE_OPTIONS=--experimental-vm-modules jest src", | ||
"type-check": "tsc --noEmit", | ||
@@ -32,37 +34,28 @@ "type-check:watch": "npm run type-check -- --watch" | ||
"lint-staged": { | ||
"*.{html,md,yml}": [ | ||
"prettier --write" | ||
], | ||
"*.{js,ts,json}": [ | ||
"eslint --fix" | ||
], | ||
".circleci/config.yml": [ | ||
".husky/validate-circleci-config.sh" | ||
] | ||
"*.{html,md,yml}": "prettier --write", | ||
"*.{js,ts,json}": "eslint --fix", | ||
".circleci/config.yml": ".husky/validate-circleci-config.sh" | ||
}, | ||
"prettier": "@shelf/prettier-config", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"natural-orderby": "3.0.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "7.18.6", | ||
"@babel/core": "7.18.6", | ||
"@shelf/babel-config": "1.0.2", | ||
"@shelf/eslint-config": "2.18.0", | ||
"@shelf/eslint-config": "3.10.0", | ||
"@shelf/prettier-config": "1.0.0", | ||
"@shelf/tsconfig": "0.0.6", | ||
"@types/jest": "28.1.5", | ||
"@types/node": "16", | ||
"babel-loader": "8.2.5", | ||
"@shelf/tsconfig": "0.0.11", | ||
"@size-limit/preset-small-lib": "10.0.2", | ||
"@types/jest": "29.5.7", | ||
"@types/node": "18", | ||
"benny": "3.7.1", | ||
"eslint": "8.19.0", | ||
"husky": "8.0.1", | ||
"jest": "28.1.3", | ||
"lint-staged": "13.0.3", | ||
"natural-orderby": "2.0.3", | ||
"prettier": "2.7.1", | ||
"typescript": "4.7.4", | ||
"webpack": "5.73.0", | ||
"webpack-cli": "4.10.0" | ||
"eslint": "8.52.0", | ||
"husky": "8.0.3", | ||
"jest": "29.7.0", | ||
"lint-staged": "15.0.2", | ||
"prettier": "3.0.3", | ||
"size-limit": "10.0.2", | ||
"typescript": "5.2.2" | ||
}, | ||
"engines": { | ||
"node": ">=14" | ||
"node": ">=18" | ||
}, | ||
@@ -69,0 +62,0 @@ "publishConfig": { |
@@ -5,2 +5,3 @@ # fast-natural-order-by [![CircleCI](https://circleci.com/gh/shelfio/fast-natural-order-by/tree/master.svg?style=svg)](https://circleci.com/gh/shelfio/fast-natural-order-by/tree/master)![](https://img.shields.io/badge/code_style-prettier-ff69b4.svg) | ||
> Note: The permormance fixes & typescript were ported into [natural-orderby](https://github.com/yobacca/natural-orderby) `>3.0.2`, so `>2` of this package just re-export the methods of natural-orderby & provide ESM only build | ||
> A fork of [natural-orderby](https://github.com/yobacca/natural-orderby) that **fixes performance when sorting strings longer than 20 characters (~150,000x faster).** | ||
@@ -7,0 +8,0 @@ > Also, re-written from Flow to Typescript |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14
526
Yes
19526
1
6
3
3
+ Addednatural-orderby@3.0.2
+ Addednatural-orderby@3.0.2(transitive)