ranges-sort
Version:
Sort string index ranges
11 lines (9 loc) • 2.09 kB
JavaScript
/**
* @name ranges-sort
* @fileoverview Sort string index ranges
* @version 6.0.14
* @author Roy Revelt, Codsen Ltd
* @license MIT
* {@link https://codsen.com/os/ranges-sort/}
*/
;var rangesSort=(()=>{var l=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames,a=Object.getOwnPropertySymbols;var c=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable;var d=(e,t,r)=>t in e?l(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,u=(e,t)=>{for(var r in t||(t={}))c.call(t,r)&&d(e,r,t[r]);if(a)for(var r of a(t))x.call(t,r)&&d(e,r,t[r]);return e};var b=(e,t)=>{for(var r in t)l(e,r,{get:t[r],enumerable:!0})},v=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of f(t))!c.call(e,o)&&o!==r&&l(e,o,{get:()=>t[o],enumerable:!(n=h(t,o))||n.enumerable});return e};var w=e=>v(l({},"__esModule",{value:!0}),e);var E={};b(E,{defaults:()=>y,rSort:()=>j,version:()=>I});var m="6.0.14";var I=m,y={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function j(e,t){if(!Array.isArray(e)||!e.length)return e;let r=u(u({},y),t),n,o;if(r.strictlyTwoElementsInRangeArrays&&!e.every((s,i)=>!Array.isArray(s)||s.length!==2?(n=i,o=s.length,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${n}th range (${JSON.stringify(e[n],null,4)}) has not two but ${o} elements!`);if(!e.every((s,i)=>!Array.isArray(s)||!Number.isInteger(s[0])||s[0]<0||!Number.isInteger(s[1])||s[1]<0?(n=i,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${n}th range (${JSON.stringify(e[n],null,4)}) does not consist of only natural numbers!`);let g=e.length**2,p=0;return Array.from(e).sort((s,i)=>(r.progressFn&&(p+=1,r.progressFn(Math.floor(p*100/g))),s[0]===i[0]?s[1]<i[1]?-1:s[1]>i[1]?1:0:s[0]<i[0]?-1:1))}return w(E);})();