Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

natural-orderby

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

natural-orderby - npm Package Compare versions

Comparing version 3.0.2 to 4.0.0

6

CHANGELOG.md
# natural-orderby
## 4.0.0
### Major Changes
- fix: update `Identifier<T>` to be `keyof T` instead of any `string`
## 3.0.2

@@ -4,0 +10,0 @@

14

dist/index.d.ts

@@ -1,9 +0,9 @@

declare type CompareFn = (valueA: unknown, valueB: unknown) => number;
declare type OrderEnum = 'asc' | 'desc';
declare type Order = OrderEnum | CompareFn;
declare type CompareOptions = {
type CompareFn = (valueA: unknown, valueB: unknown) => number;
type OrderEnum = 'asc' | 'desc';
type Order = OrderEnum | CompareFn;
type CompareOptions = {
order?: OrderEnum;
} | OrderEnum | undefined;
declare type IdentifierFn<T> = (value: T) => unknown;
declare type Identifier<T> = IdentifierFn<T> | string | number;
type IdentifierFn<T> = (value: T) => unknown;
type Identifier<T> = IdentifierFn<T> | keyof T | number;

@@ -24,2 +24,2 @@ /**

export { CompareFn, CompareOptions, Identifier, Order, compare, orderBy };
export { type CompareFn, type CompareOptions, type Identifier, type Order, compare, orderBy };
/**
* natural-orderby v3.0.2
* natural-orderby v4.0.0
*

@@ -4,0 +4,0 @@ * Copyright (c) Olaf Ennen

/**
* natural-orderby v3.0.2
* natural-orderby v4.0.0
*

@@ -13,3 +13,3 @@ * Copyright (c) Olaf Ennen

/* eslint-env node */
/* eslint-disable n/no-missing-require */

@@ -16,0 +16,0 @@ if (process.env.NODE_ENV === 'production') {

/**
* natural-orderby v3.0.2
* natural-orderby v4.0.0
*

@@ -4,0 +4,0 @@ * Copyright (c) Olaf Ennen

/**
* natural-orderby v3.0.2
* natural-orderby v4.0.0
*

@@ -11,2 +11,2 @@ * Copyright (c) Olaf Ennen

*/
const e=(e,r)=>e<r?-1:e>r?1:0,r=(e,r)=>{const n=e.localeCompare(r);return n?n/Math.abs(n):0},n=/(^0x[\da-fA-F]+$|^([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?(?!\.\d+)(?=\D|\s|$))|\d+)/g,t=/^\s+|\s+$/g,i=/\s+/g,s=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/,o=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[/-]\d{1,4}[/-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,a=/^0+[1-9]{1}[0-9]*$/,u=/[^\x00-\x80]/,c=(e,r)=>e<r?-1:e>r?1:0,l=(n,t)=>n.value===t.value?0:void 0!==n.parsedNumber&&void 0!==t.parsedNumber?e(n.parsedNumber,t.parsedNumber):n.chunks&&t.chunks?((n,t)=>{const i=n.length,s=t.length,o=Math.min(i,s);for(let a=0;a<o;a++){const i=n[a],s=t[a];if(i.normalizedString!==s.normalizedString){if(""===i.normalizedString!=(""===s.normalizedString))return""===i.normalizedString?-1:1;if(void 0!==i.parsedNumber&&void 0!==s.parsedNumber){const r=e(i.parsedNumber,s.parsedNumber);return 0===r?c(i.normalizedString,s.normalizedString):r}return void 0!==i.parsedNumber||void 0!==s.parsedNumber?void 0!==i.parsedNumber?-1:1:u.test(i.normalizedString+s.normalizedString)?r(i.normalizedString,s.normalizedString):c(i.normalizedString,s.normalizedString)}}return i>o||s>o?i<=o?-1:1:0})(n.chunks,t.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)(n,t),d=e=>e.replace(i," ").replace(t,""),f=e=>{if(0!==e.length){const r=Number(e);if(!Number.isNaN(r))return r}},m=(e,r,n)=>{if(s.test(e)&&(!a.test(e)||0===r||"."!==n[r-1]))return f(e)||0},p=(e,r,n)=>({parsedNumber:m(e,r,n),normalizedString:d(e)}),N=e=>{const r=(e=>e.replace(n,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"))(e).map(p);return r},b=e=>"function"==typeof e,y=e=>Number.isNaN(e)||e instanceof Number&&Number.isNaN(e.valueOf()),g=e=>null===e,S=e=>!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof Number||e instanceof String||e instanceof Boolean||e instanceof Date),v=e=>"symbol"==typeof e,h=e=>void 0===e,A=e=>{const r=f(e);return void 0!==r?r:(e=>{try{const r=Date.parse(e);return!Number.isNaN(r)&&o.test(e)?r:void 0}catch{return}})(e)},z=e=>{if("string"==typeof e||e instanceof String||("number"==typeof e||e instanceof Number)&&!y(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(t,""):"")(e),n=A(r);return{parsedNumber:n,chunks:N(n?`${n}`:r),value:e}}return{isArray:Array.isArray(e),isFunction:b(e),isNaN:y(e),isNull:g(e),isObject:S(e),isSymbol:v(e),isUndefined:h(e),value:e}},j=e=>"string"==typeof e&&("asc"===e||"desc"===e);function k(e){return(e=>(r,n)=>{const t=z(r),i=z(n);return l(t,i)*("desc"===e.order?-1:1)})((e=>{let r="asc";return"string"==typeof e&&j(e)?r=e:e&&"object"==typeof e&&e.order&&j(e.order)&&({order:r}=e),{order:r}})(e))}const w=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){return Object.getOwnPropertyDescriptor(r,e)?.value}return r},x=(e,r,n)=>{const t=r.length?r.map(w):[e=>e],i=e.map(((e,r)=>({index:r,values:t.map((r=>r(e))).map(z)})));return i.sort(((e,r)=>((e,r,n)=>{const{index:t,values:i}=e,{index:s,values:o}=r,{length:a}=i,u=n.length;for(let c=0;c<a;c++){const e=c<u?n[c]:null;if(e&&"function"==typeof e){const r=e(i[c].value,o[c].value);if(r)return r}else{const r=l(i[c],o[c]);if(r)return r*("desc"===e?-1:1)}}return t-s})(e,r,n))),i.map((r=>((e,r)=>e[r])(e,r.index)))};function O(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),i=(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 x(e,t,i)}export{k as compare,O as orderBy};
const e=(e,r)=>e<r?-1:e>r?1:0,r=(e,r)=>{const n=e.localeCompare(r);return n?n/Math.abs(n):0},n=/(^0x[\da-fA-F]+$|^([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?(?!\.\d+)(?=\D|\s|$))|\d+)/g,t=/^\s+|\s+$/g,i=/\s+/g,s=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/,o=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[/-]\d{1,4}[/-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,a=/^0+[1-9]{1}[0-9]*$/,u=/[^\x00-\x80]/,c=(e,r)=>e<r?-1:e>r?1:0,l=(n,t)=>n.value===t.value?0:void 0!==n.parsedNumber&&void 0!==t.parsedNumber?e(n.parsedNumber,t.parsedNumber):n.chunks&&t.chunks?((n,t)=>{const i=n.length,s=t.length,o=Math.min(i,s);for(let a=0;a<o;a++){const i=n[a],s=t[a];if(i.normalizedString!==s.normalizedString){if(""===i.normalizedString!=(""===s.normalizedString))return""===i.normalizedString?-1:1;if(void 0!==i.parsedNumber&&void 0!==s.parsedNumber){const r=e(i.parsedNumber,s.parsedNumber);return 0===r?c(i.normalizedString,s.normalizedString):r}return void 0!==i.parsedNumber||void 0!==s.parsedNumber?void 0!==i.parsedNumber?-1:1:u.test(i.normalizedString+s.normalizedString)?r(i.normalizedString,s.normalizedString):c(i.normalizedString,s.normalizedString)}}return i>o||s>o?i<=o?-1:1:0})(n.chunks,t.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)(n,t),d=e=>e.replace(i," ").replace(t,""),f=e=>{if(0!==e.length){const r=Number(e);if(!Number.isNaN(r))return r}},m=(e,r,n)=>{if(s.test(e)&&(!a.test(e)||0===r||"."!==n[r-1]))return f(e)||0},p=(e,r,n)=>({parsedNumber:m(e,r,n),normalizedString:d(e)}),N=e=>{const r=(e=>e.replace(n,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"))(e).map(p);return r},b=e=>"function"==typeof e,y=e=>Number.isNaN(e)||e instanceof Number&&Number.isNaN(e.valueOf()),g=e=>null===e,S=e=>!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof Number||e instanceof String||e instanceof Boolean||e instanceof Date),v=e=>"symbol"==typeof e,h=e=>void 0===e,A=e=>{const r=f(e);return void 0!==r?r:(e=>{try{const r=Date.parse(e);return!Number.isNaN(r)&&o.test(e)?r:void 0}catch{return}})(e)},z=e=>{if("string"==typeof e||e instanceof String||("number"==typeof e||e instanceof Number)&&!y(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(t,""):"")(e),n=A(r);return{parsedNumber:n,chunks:N(n?`${n}`:r),value:e}}return{isArray:Array.isArray(e),isFunction:b(e),isNaN:y(e),isNull:g(e),isObject:S(e),isSymbol:v(e),isUndefined:h(e),value:e}},j=e=>"string"==typeof e&&("asc"===e||"desc"===e);function k(e){return(e=>(r,n)=>{const t=z(r),i=z(n);return l(t,i)*("desc"===e.order?-1:1)})((e=>{let r="asc";return"string"==typeof e&&j(e)?r=e:e&&"object"==typeof e&&e.order&&j(e.order)&&({order:r}=e),{order:r}})(e))}const w=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){const n=Object.getOwnPropertyDescriptor(r,e);return n?.value}return r},x=(e,r,n)=>{const t=r.length?r.map(w):[e=>e],i=e.map(((e,r)=>({index:r,values:t.map((r=>r(e))).map(z)})));return i.sort(((e,r)=>((e,r,n)=>{const{index:t,values:i}=e,{index:s,values:o}=r,{length:a}=i,u=n.length;for(let c=0;c<a;c++){const e=c<u?n[c]:null;if(e&&"function"==typeof e){const r=e(i[c].value,o[c].value);if(r)return r}else{const r=l(i[c],o[c]);if(r)return r*("desc"===e?-1:1)}}return t-s})(e,r,n))),i.map((r=>((e,r)=>e[r])(e,r.index)))};function O(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),i=(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 x(e,t,i)}export{k as compare,O as orderBy};
/**
* natural-orderby v3.0.2
* natural-orderby v4.0.0
*

@@ -413,4 +413,2 @@ * Copyright (c) Olaf Ennen

Object.defineProperty(exports, '__esModule', { value: true });
}));
/**
* natural-orderby v3.0.2
* natural-orderby v4.0.0
*

@@ -11,2 +11,2 @@ * Copyright (c) Olaf Ennen

*/
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((r="undefined"!=typeof globalThis?globalThis:r||self).naturalOrderBy={})}(this,(function(r){"use strict";var n=function(r,n){return r<n?-1:r>n?1:0},e=function(r,n){var e=r.localeCompare(n);return e?e/Math.abs(e):0},t=/(^0x[\da-fA-F]+$|^([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?(?!\.\d+)(?=\D|\s|$))|\d+)/g,i=/^\s+|\s+$/g,u=/\s+/g,o=/^[+-]?(?:\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})/,s=/^0+[1-9]{1}[0-9]*$/,f=/[^\x00-\x80]/,c=function(r,n){return r<n?-1:r>n?1:0},d=function(r,t){return r.value===t.value?0:void 0!==r.parsedNumber&&void 0!==t.parsedNumber?n(r.parsedNumber,t.parsedNumber):r.chunks&&t.chunks?function(r,t){for(var i=r.length,u=t.length,o=Math.min(i,u),a=0;a<o;a++){var s=r[a],d=t[a];if(s.normalizedString!==d.normalizedString){if(""===s.normalizedString!=(""===d.normalizedString))return""===s.normalizedString?-1:1;if(void 0!==s.parsedNumber&&void 0!==d.parsedNumber){var l=n(s.parsedNumber,d.parsedNumber);return 0===l?c(s.normalizedString,d.normalizedString):l}return void 0!==s.parsedNumber||void 0!==d.parsedNumber?void 0!==s.parsedNumber?-1:1:f.test(s.normalizedString+d.normalizedString)?e(s.normalizedString,d.normalizedString):c(s.normalizedString,d.normalizedString)}}return i>o||u>o?i<=o?-1:1:0}(r.chunks,t.chunks):function(r,n){return(r.chunks?!n.chunks:n.chunks)?r.chunks?-1:1:(r.isNaN?!n.isNaN:n.isNaN)?r.isNaN?-1:1:(r.isSymbol?!n.isSymbol:n.isSymbol)?r.isSymbol?-1:1:(r.isObject?!n.isObject:n.isObject)?r.isObject?-1:1:(r.isArray?!n.isArray:n.isArray)?r.isArray?-1:1:(r.isFunction?!n.isFunction:n.isFunction)?r.isFunction?-1:1:(r.isNull?!n.isNull:n.isNull)?r.isNull?-1:1:0}(r,t)},l=function(r){return r.replace(u," ").replace(i,"")},m=function(r){if(0!==r.length){var n=Number(r);if(!Number.isNaN(n))return n}},p=function(r,n,e){if(o.test(r)&&(!s.test(r)||0===n||"."!==e[n-1]))return m(r)||0},y=function(r,n,e){return{parsedNumber:p(r,n,e),normalizedString:l(r)}},b=function(r){var n=function(r){return r.replace(t,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0")}(r).map(y);return n},N=function(r){return"function"==typeof r},v=function(r){return Number.isNaN(r)||r instanceof Number&&Number.isNaN(r.valueOf())},g=function(r){return null===r},S=function(r){return!(null===r||"object"!=typeof r||Array.isArray(r)||r instanceof Number||r instanceof String||r instanceof Boolean||r instanceof Date)},h=function(r){return"symbol"==typeof r},A=function(r){return void 0===r},z=function(r){var n=m(r);return void 0!==n?n:function(r){try{var n=Date.parse(r);return!Number.isNaN(n)&&a.test(r)?n:void 0}catch(r){return}}(r)},j=function(r){if("string"==typeof r||r instanceof String||("number"==typeof r||r instanceof Number)&&!v(r)||"boolean"==typeof r||r instanceof Boolean||r instanceof Date){var n=function(r){return"boolean"==typeof r||r instanceof Boolean?Number(r).toString():"number"==typeof r||r instanceof Number?r.toString():r instanceof Date?r.getTime().toString():"string"==typeof r||r instanceof String?r.toLowerCase().replace(i,""):""}(r),e=z(n);return{parsedNumber:e,chunks:b(e?""+e:n),value:r}}return{isArray:Array.isArray(r),isFunction:N(r),isNaN:v(r),isNull:g(r),isObject:S(r),isSymbol:h(r),isUndefined:A(r),value:r}},x=function(r){return"string"==typeof r&&("asc"===r||"desc"===r)};var O=function(r){return"function"==typeof r?r:function(n){if(Array.isArray(n)){var e=Number(r);if(Number.isInteger(e))return n[e]}else if(n&&"object"==typeof n){var t=Object.getOwnPropertyDescriptor(n,r);return null==t?void 0:t.value}return n}},k=function(r,n,e){var t=n.length?n.map(O):[function(r){return r}],i=r.map((function(r,n){return{index:n,values:t.map((function(n){return n(r)})).map(j)}}));return i.sort((function(r,n){return function(r,n,e){for(var t=r.index,i=r.values,u=n.index,o=n.values,a=i.length,s=e.length,f=0;f<a;f++){var c=f<s?e[f]:null;if(c&&"function"==typeof c){var l=c(i[f].value,o[f].value);if(l)return l}else{var m=d(i[f],o[f]);if(m)return m*("desc"===c?-1:1)}}return t-u}(r,n,e)})),i.map((function(n){return function(r,n){return r[n]}(r,n.index)}))};r.compare=function(r){var n,e;return function(r){return function(n,e){var t=j(n),i=j(e);return d(t,i)*("desc"===r.order?-1:1)}}((e="asc","string"==typeof(n=r)&&x(n)?e=n:n&&"object"==typeof n&&n.order&&x(n.order)&&(e=n.order),{order:e}))},r.orderBy=function(r,n,e){if(!r||!Array.isArray(r))return[];var t=function(r){if(!r)return[];var n=Array.isArray(r)?[].concat(r):[r];return n.some((function(r){return"string"!=typeof r&&"number"!=typeof r&&"function"!=typeof r}))?[]:n}(n),i=function(r){if(!r)return[];var n=Array.isArray(r)?[].concat(r):[r];return n.some((function(r){return"asc"!==r&&"desc"!==r&&"function"!=typeof r}))?[]:n}(e);return k(r,t,i)},Object.defineProperty(r,"__esModule",{value:!0})}));
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((r="undefined"!=typeof globalThis?globalThis:r||self).naturalOrderBy={})}(this,(function(r){"use strict";var n=function(r,n){return r<n?-1:r>n?1:0},e=function(r,n){var e=r.localeCompare(n);return e?e/Math.abs(e):0},t=/(^0x[\da-fA-F]+$|^([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?(?!\.\d+)(?=\D|\s|$))|\d+)/g,i=/^\s+|\s+$/g,u=/\s+/g,o=/^[+-]?(?:\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})/,s=/^0+[1-9]{1}[0-9]*$/,f=/[^\x00-\x80]/,c=function(r,n){return r<n?-1:r>n?1:0},d=function(r,t){return r.value===t.value?0:void 0!==r.parsedNumber&&void 0!==t.parsedNumber?n(r.parsedNumber,t.parsedNumber):r.chunks&&t.chunks?function(r,t){for(var i=r.length,u=t.length,o=Math.min(i,u),a=0;a<o;a++){var s=r[a],d=t[a];if(s.normalizedString!==d.normalizedString){if(""===s.normalizedString!=(""===d.normalizedString))return""===s.normalizedString?-1:1;if(void 0!==s.parsedNumber&&void 0!==d.parsedNumber){var l=n(s.parsedNumber,d.parsedNumber);return 0===l?c(s.normalizedString,d.normalizedString):l}return void 0!==s.parsedNumber||void 0!==d.parsedNumber?void 0!==s.parsedNumber?-1:1:f.test(s.normalizedString+d.normalizedString)?e(s.normalizedString,d.normalizedString):c(s.normalizedString,d.normalizedString)}}return i>o||u>o?i<=o?-1:1:0}(r.chunks,t.chunks):function(r,n){return(r.chunks?!n.chunks:n.chunks)?r.chunks?-1:1:(r.isNaN?!n.isNaN:n.isNaN)?r.isNaN?-1:1:(r.isSymbol?!n.isSymbol:n.isSymbol)?r.isSymbol?-1:1:(r.isObject?!n.isObject:n.isObject)?r.isObject?-1:1:(r.isArray?!n.isArray:n.isArray)?r.isArray?-1:1:(r.isFunction?!n.isFunction:n.isFunction)?r.isFunction?-1:1:(r.isNull?!n.isNull:n.isNull)?r.isNull?-1:1:0}(r,t)},l=function(r){return r.replace(u," ").replace(i,"")},m=function(r){if(0!==r.length){var n=Number(r);if(!Number.isNaN(n))return n}},p=function(r,n,e){if(o.test(r)&&(!s.test(r)||0===n||"."!==e[n-1]))return m(r)||0},y=function(r,n,e){return{parsedNumber:p(r,n,e),normalizedString:l(r)}},b=function(r){var n=function(r){return r.replace(t,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0")}(r).map(y);return n},N=function(r){return"function"==typeof r},v=function(r){return Number.isNaN(r)||r instanceof Number&&Number.isNaN(r.valueOf())},g=function(r){return null===r},S=function(r){return!(null===r||"object"!=typeof r||Array.isArray(r)||r instanceof Number||r instanceof String||r instanceof Boolean||r instanceof Date)},h=function(r){return"symbol"==typeof r},A=function(r){return void 0===r},z=function(r){var n=m(r);return void 0!==n?n:function(r){try{var n=Date.parse(r);return!Number.isNaN(n)&&a.test(r)?n:void 0}catch(r){return}}(r)},j=function(r){if("string"==typeof r||r instanceof String||("number"==typeof r||r instanceof Number)&&!v(r)||"boolean"==typeof r||r instanceof Boolean||r instanceof Date){var n=function(r){return"boolean"==typeof r||r instanceof Boolean?Number(r).toString():"number"==typeof r||r instanceof Number?r.toString():r instanceof Date?r.getTime().toString():"string"==typeof r||r instanceof String?r.toLowerCase().replace(i,""):""}(r),e=z(n);return{parsedNumber:e,chunks:b(e?""+e:n),value:r}}return{isArray:Array.isArray(r),isFunction:N(r),isNaN:v(r),isNull:g(r),isObject:S(r),isSymbol:h(r),isUndefined:A(r),value:r}},x=function(r){return"string"==typeof r&&("asc"===r||"desc"===r)};var k=function(r){return"function"==typeof r?r:function(n){if(Array.isArray(n)){var e=Number(r);if(Number.isInteger(e))return n[e]}else if(n&&"object"==typeof n){var t=Object.getOwnPropertyDescriptor(n,r);return null==t?void 0:t.value}return n}},w=function(r,n,e){var t=n.length?n.map(k):[function(r){return r}],i=r.map((function(r,n){return{index:n,values:t.map((function(n){return n(r)})).map(j)}}));return i.sort((function(r,n){return function(r,n,e){for(var t=r.index,i=r.values,u=n.index,o=n.values,a=i.length,s=e.length,f=0;f<a;f++){var c=f<s?e[f]:null;if(c&&"function"==typeof c){var l=c(i[f].value,o[f].value);if(l)return l}else{var m=d(i[f],o[f]);if(m)return m*("desc"===c?-1:1)}}return t-u}(r,n,e)})),i.map((function(n){return function(r,n){return r[n]}(r,n.index)}))};r.compare=function(r){var n,e;return function(r){return function(n,e){var t=j(n),i=j(e);return d(t,i)*("desc"===r.order?-1:1)}}((e="asc","string"==typeof(n=r)&&x(n)?e=n:n&&"object"==typeof n&&n.order&&x(n.order)&&(e=n.order),{order:e}))},r.orderBy=function(r,n,e){if(!r||!Array.isArray(r))return[];var t=function(r){if(!r)return[];var n=Array.isArray(r)?[].concat(r):[r];return n.some((function(r){return"string"!=typeof r&&"number"!=typeof r&&"function"!=typeof r}))?[]:n}(n),i=function(r){if(!r)return[];var n=Array.isArray(r)?[].concat(r):[r];return n.some((function(r){return"asc"!==r&&"desc"!==r&&"function"!=typeof r}))?[]:n}(e);return w(r,t,i)}}));
{
"name": "natural-orderby",
"version": "3.0.2",
"version": "4.0.0",
"description": "Lightweight and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc.",

@@ -20,5 +20,6 @@ "sideEffects": false,

"test": "cross-env TZ=UTC jest src",
"typecheck": "tsc --noEmit --emitDeclarationOnly false",
"size": "filesize",
"prepublishOnly": "yarn build",
"prepare": "husky install"
"prepare": "husky"
},

@@ -73,30 +74,28 @@ "files": [

"@changesets/cli": "^2.25.2",
"@commitlint/cli": "^17.2.0",
"@commitlint/config-conventional": "^17.2.0",
"@commitlint/types": "^17.0.0",
"@commitlint/cli": "^19.4.0",
"@commitlint/config-conventional": "^19.2.2",
"@commitlint/types": "^19.0.3",
"@rollup/plugin-babel": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.3.0",
"@types/jest": "29.2.6",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"babel-eslint": "^10.1.0",
"babel-jest": "^29.3.1",
"@rollup/plugin-terser": "^0.4.4",
"@types/jest": "29.5.13",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"cross-env": "^7.0.3",
"docsify-cli": "^4.3.0",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^27.1.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^8.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.8.0",
"eslint-plugin-n": "^17.10.2",
"eslint-plugin-prettier": "^5.2.1",
"husky": "^9.1.5",
"jest": "^29.3.1",
"lint-staged": "^13.0.3",
"prettier": "^2.5.1",
"rollup": "^2.79.1",
"lint-staged": "^15.2.9",
"prettier": "^3.3.3",
"rollup": "^4.21.1",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-dts": "^5.0.0",
"rollup-plugin-dts": "^6.1.1",
"ts-jest": "^29.0.3",
"typescript": "^4.7.3"
"typescript": "^5.5.4"
},

@@ -103,0 +102,0 @@ "lint-staged": {

@@ -1,9 +0,9 @@

# Welcome to 🌲 natural-orderby &middot; [![npm package][npm-badge]][npm] [![build][build-badge]][build]
# Welcome to 🌲 natural-orderby
[npm-badge]: https://img.shields.io/npm/v/natural-orderby.svg?style=flat-square
[npm]: https://www.npmjs.org/package/natural-orderby
[build-badge]: https://img.shields.io/github/workflow/status/yobacca/natural-orderby/test/main?style=flat-square
[build]: https://github.com/yobacca/natural-orderby/actions/workflows/test.yml
Lightweight (< 1.6kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc.
> Lightweight (< 1.6kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc.
[![npm version](https://img.shields.io/npm/v/natural-orderby.svg)](https://www.npmjs.com/package/natural-orderby)
[![downloads](https://img.shields.io/npm/dm/natural-orderby.svg)](https://www.npmjs.com/package/natural-orderby)
[![CI](https://github.com/yobacca/natural-orderby/workflows/CI/badge.svg)](https://github.com/yobacca/natural-orderby/actions)
[![coverage](https://img.shields.io/codecov/c/github/yobacca/natural-orderby.svg)](https://codecov.io/gh/yobacca/natural-orderby)

@@ -152,3 +152,3 @@ People sort strings containing numbers differently than most sorting algorithms, which sort values by comparing strings in Unicode code point order. This produces an ordering that is inconsistent with human logic.

| :-------------- | :----------------------------------------------------------------------------------- |
| `Identifier<T>` | <code>string &#124; number &#124; (value: T) => unknown</code> |
| `Identifier<T>` | <code>keyof T &#124; number &#124; (value: T) => unknown</code> |
| `Order` | <code>'asc' &#124; 'desc' &#124; (valueA: unknown, valueB: unknown) => number</code> |

@@ -155,0 +155,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc