UNPKG

ranges-regex

Version:

Integrate regex operations into Ranges workflow

41 lines (38 loc) 7.13 kB
/** * @name ranges-regex * @fileoverview Integrate regex operations into Ranges workflow * @version 6.0.20 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ranges-regex/} */ "use strict";var rangesRegex=(()=>{var x=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames,T=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var w=(e,r,f)=>r in e?x(e,r,{enumerable:!0,configurable:!0,writable:!0,value:f}):e[r]=f,d=(e,r)=>{for(var f in r||(r={}))v.call(r,f)&&w(e,f,r[f]);if(T)for(var f of T(r))q.call(r,f)&&w(e,f,r[f]);return e};var L=(e,r)=>{for(var f in r)x(e,f,{get:r[f],enumerable:!0})},P=(e,r,f,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of M(r))!v.call(e,l)&&l!==f&&x(e,l,{get:()=>r[l],enumerable:!(o=$(r,l))||o.enumerable});return e};var C=e=>P(x({},"__esModule",{value:!0}),e);var ie={};L(ie,{rRegex:()=>me,version:()=>ne});var H={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function c(e,r){if(!Array.isArray(e)||!e.length)return e;let f=d(d({},H),r),o,l;if(f.strictlyTwoElementsInRangeArrays&&!e.every((s,p)=>!Array.isArray(s)||s.length!==2?(o=p,l=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, ${o}th range (${JSON.stringify(e[o],null,4)}) has not two but ${l} elements!`);if(!e.every((s,p)=>!Array.isArray(s)||!Number.isInteger(s[0])||s[0]<0||!Number.isInteger(s[1])||s[1]<0?(o=p,!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, ${o}th range (${JSON.stringify(e[o],null,4)}) does not consist of only natural numbers!`);let a=e.length**2,u=0;return Array.from(e).sort((s,p)=>(f.progressFn&&(u+=1,f.progressFn(Math.floor(u*100/a))),s[0]===p[0]?s[1]<p[1]?-1:s[1]>p[1]?1:0:s[0]<p[0]?-1:1))}var R={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function j(e,r){function f(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}if(!Array.isArray(e)||!e.length)return null;let o;if(r)if(f(r)){if(o=d(d({},R),r),o.progressFn&&f(o.progressFn)&&!Object.keys(o.progressFn).length)o.progressFn=null;else if(o.progressFn&&typeof o.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof o.progressFn}", equal to ${JSON.stringify(o.progressFn,null,4)}`);if(![1,2,"1","2"].includes(o.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof o.mergeType}", equal to ${JSON.stringify(o.mergeType,null,4)}`);if(typeof o.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof o.joinRangesThatTouchEdges}", equal to ${JSON.stringify(o.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as: ${JSON.stringify(r,null,4)} (type ${typeof r})`);else o=d({},R);let l=e.filter(t=>Array.isArray(t)).map(t=>[...t]).filter(t=>t[2]!==void 0||t[0]!==t[1]),a,u,s;o.progressFn?a=c(l,{progressFn:t=>{s=Math.floor(t/5),s!==u&&(u=s,o.progressFn(s))}}):a=c(l);let p=a.length-1;for(let t=p;t>0;t--)o.progressFn&&(s=Math.floor((1-t/p)*78)+21,s!==u&&s>u&&(u=s,o.progressFn(s))),(a[t][0]<=a[t-1][0]||!o.joinRangesThatTouchEdges&&a[t][0]<a[t-1][1]||o.joinRangesThatTouchEdges&&a[t][0]<=a[t-1][1])&&(a[t-1][0]=Math.min(a[t][0],a[t-1][0]),a[t-1][1]=Math.max(a[t][1],a[t-1][1]),a[t][2]!==void 0&&(a[t-1][0]>=a[t][0]||a[t-1][1]<=a[t][1])&&a[t-1][2]!==null&&(a[t][2]===null&&a[t-1][2]!==null?a[t-1][2]=null:a[t-1][2]!=null?+o.mergeType==2&&a[t-1][0]===a[t][0]?a[t-1][2]=a[t][2]:a[t-1][2]+=a[t][2]:a[t-1][2]=a[t][2]),a.splice(t,1),t=a.length);return a.length?a:null}var z=typeof global=="object"&&global&&global.Object===Object&&global,g=z;var J=typeof self=="object"&&self&&self.Object===Object&&self,U=g||J||Function("return this")(),I=U;var G=I.Symbol,n=G;var O=Object.prototype,K=O.hasOwnProperty,V=O.toString,m=n?n.toStringTag:void 0;function Q(e){var r=K.call(e,m),f=e[m];try{e[m]=void 0;var o=!0}catch(a){}var l=V.call(e);return o&&(r?e[m]=f:delete e[m]),l}var S=Q;var X=Object.prototype,Y=X.toString;function Z(e){return Y.call(e)}var W=Z;var ee="[object Null]",te="[object Undefined]",E=n?n.toStringTag:void 0;function re(e){return e==null?e===void 0?te:ee:E&&E in Object(e)?S(e):W(e)}var A=re;function oe(e){return e!=null&&typeof e=="object"}var k=oe;function ae(e){return function(r){return e(r)}}var F=ae;var B=typeof exports=="object"&&exports&&!exports.nodeType&&exports,i=B&&typeof module=="object"&&module&&!module.nodeType&&module,fe=i&&i.exports===B,y=fe&&g.process,se=function(){try{var e=i&&i.require&&i.require("util").types;return e||y&&y.binding&&y.binding("util")}catch(r){}}(),h=se;var le="[object RegExp]";function pe(e){return k(e)&&A(e)==le}var D=pe;var N=h&&h.isRegExp,ue=N?F(N):D,b=ue;var _="6.0.20";var ne=_;function me(e,r,f){if(e===void 0)throw new TypeError("ranges-regex: [THROW_ID_01] The first input's argument must be a regex object! Currently it is missing!");if(!b(e))throw new TypeError(`ranges-regex: [THROW_ID_02] The first input's argument must be a regex object! Currently its type is: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(typeof r!="string")throw new TypeError(`ranges-regex: [THROW_ID_03] The second input's argument must be a string! Currently its type is: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(f&&typeof f!="string")throw new TypeError(`ranges-regex: [THROW_ID_04] The third input's argument must be a string or null! Currently its type is: ${typeof f}, equal to: ${JSON.stringify(f,null,4)}`);if(!r.length)return null;let o,l=[];if(f===null||typeof f=="string"&&f.length)for(;(o=e.exec(r))!==null;)l.push([e.lastIndex-o[0].length,e.lastIndex,f]);else for(;(o=e.exec(r))!==null;)l.push([e.lastIndex-o[0].length,e.lastIndex]);return l.length?j(l):null}return C(ie);})(); /** * @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/} */ /** * @name ranges-merge * @fileoverview Merge and sort string index ranges * @version 9.0.19 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ranges-merge/} */ /*! Bundled license information: lodash-es/lodash.js: (** * @license * Lodash (Custom Build) <https://lodash.com/> * Build: `lodash modularize exports="es" -o ./` * Copyright OpenJS Foundation and other contributors <https://openjsf.org/> * Released under MIT license <https://lodash.com/license> * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors *) */