json-variables 11.0.2 → 11.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/json-variables.esm.js +5 -4
- package/dist/json-variables.umd.js +26 -26
- package/package.json +42 -42
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 11.0.3 (2021-11-02)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- bump TS and separate ESLint plugins away from this monorepo ([b1ebce1](https://github.com/codsen/codsen/commit/b1ebce1637d8c41c2d848fc24b0ba4058865bd5d))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- migrate to ES Modules ([c579dff](https://github.com/codsen/codsen/commit/c579dff3b23205e383035ca10ddcec671e35d0fe))
|
|
15
|
+
|
|
16
|
+
### BREAKING CHANGES
|
|
17
|
+
|
|
18
|
+
- programs now are in ES Modules and won't work with Common JS require()
|
|
19
|
+
|
|
6
20
|
## 11.0.1 (2021-09-13)
|
|
7
21
|
|
|
8
22
|
### Bug Fixes
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name json-variables
|
|
3
3
|
* @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
|
|
4
|
-
* @version 11.0.
|
|
4
|
+
* @version 11.0.3
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/json-variables/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { traverse } from 'ast-monkey-traverse';
|
|
11
|
-
import
|
|
11
|
+
import { isMatch } from 'matcher';
|
|
12
12
|
import objectPath from 'object-path';
|
|
13
13
|
import { arrayiffy } from 'arrayiffy-if-string';
|
|
14
14
|
import { strFindHeadsTails } from 'string-find-heads-tails';
|
|
@@ -18,7 +18,7 @@ import { rApply } from 'ranges-apply';
|
|
|
18
18
|
import { remDup } from 'string-remove-duplicate-heads-tails';
|
|
19
19
|
import { matchRightIncl, matchLeftIncl } from 'string-match-left-right';
|
|
20
20
|
|
|
21
|
-
var version$1 = "11.0.
|
|
21
|
+
var version$1 = "11.0.3";
|
|
22
22
|
|
|
23
23
|
const version = version$1;
|
|
24
24
|
const has = Object.prototype.hasOwnProperty;
|
|
@@ -137,7 +137,8 @@ function wrap(placementValue, opts, dontWrapTheseVars = false, breadCrumbPath, n
|
|
|
137
137
|
if (!opts.wrapTailsWith) {
|
|
138
138
|
opts.wrapTailsWith = "";
|
|
139
139
|
}
|
|
140
|
-
if (isStr(placementValue) && !dontWrapTheseVars && opts.wrapGlobalFlipSwitch && !opts.dontWrapVars.some(val =>
|
|
140
|
+
if (isStr(placementValue) && !dontWrapTheseVars && opts.wrapGlobalFlipSwitch && !opts.dontWrapVars.some(val => isMatch(oldVarName, val)) && (
|
|
141
|
+
!opts.preventDoubleWrapping || opts.preventDoubleWrapping && isStr(placementValue) && !placementValue.includes(opts.wrapHeadsWith) && !placementValue.includes(opts.wrapTailsWith))) {
|
|
141
142
|
return opts.wrapHeadsWith + placementValue + opts.wrapTailsWith;
|
|
142
143
|
}
|
|
143
144
|
if (dontWrapTheseVars) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name json-variables
|
|
3
3
|
* @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
|
|
4
|
-
* @version 11.0.
|
|
4
|
+
* @version 11.0.3
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/json-variables/}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
/**
|
|
12
12
|
* @name ast-monkey-util
|
|
13
13
|
* @fileoverview Utility library of AST helper functions
|
|
14
|
-
* @version 2.0.
|
|
14
|
+
* @version 2.0.3
|
|
15
15
|
* @author Roy Revelt, Codsen Ltd
|
|
16
16
|
* @license MIT
|
|
17
17
|
* {@link https://codsen.com/os/ast-monkey-util/}
|
|
@@ -19,96 +19,96 @@
|
|
|
19
19
|
/**
|
|
20
20
|
* @name ast-monkey-traverse
|
|
21
21
|
* @fileoverview Utility library to traverse AST
|
|
22
|
-
* @version 3.0.
|
|
22
|
+
* @version 3.0.3
|
|
23
23
|
* @author Roy Revelt, Codsen Ltd
|
|
24
24
|
* @license MIT
|
|
25
25
|
* {@link https://codsen.com/os/ast-monkey-traverse/}
|
|
26
|
-
*/function p(e,t){return function e(t,r,i,s){const o=n(t);let a;const l={depth:-1,path:"",...i};if(l.depth+=1,Array.isArray(o))for(let t=0,i=o.length;t<i&&!s.now;t++){const i=l.path?`${l.path}.${t}`:`${t}`;void 0!==o[t]?(l.parent=n(o),l.parentType="array",l.parentKey=g(i),a=e(r(o[t],void 0,{...l,path:i},s),r,{...l,path:i},s),Number.isNaN(a)&&t<o.length?(o.splice(t,1),t-=1):o[t]=a):o.splice(t,1)}else if(c(o))for(const t in o){if(s.now&&null!=t)break;const i=l.path?`${l.path}.${t}`:t;0===l.depth&&null!=t&&(l.topmostKey=t),l.parent=n(o),l.parentType="object",l.parentKey=g(i),a=e(r(t,o[t],{...l,path:i},s),r,{...l,path:i},s),Number.isNaN(a)?delete o[t]:o[t]=a}return o}(e,t,{},{now:!1})}
|
|
26
|
+
*/function p(e,t){return function e(t,r,i,s){const o=n(t);let a;const l={depth:-1,path:"",...i};if(l.depth+=1,Array.isArray(o))for(let t=0,i=o.length;t<i&&!s.now;t++){const i=l.path?`${l.path}.${t}`:`${t}`;void 0!==o[t]?(l.parent=n(o),l.parentType="array",l.parentKey=g(i),a=e(r(o[t],void 0,{...l,path:i},s),r,{...l,path:i},s),Number.isNaN(a)&&t<o.length?(o.splice(t,1),t-=1):o[t]=a):o.splice(t,1)}else if(c(o))for(const t in o){if(s.now&&null!=t)break;const i=l.path?`${l.path}.${t}`:t;0===l.depth&&null!=t&&(l.topmostKey=t),l.parent=n(o),l.parentType="object",l.parentKey=g(i),a=e(r(t,o[t],{...l,path:i},s),r,{...l,path:i},s),Number.isNaN(a)?delete o[t]:o[t]=a}return o}(e,t,{},{now:!1})}const y=new Map,d=(e,t)=>{if(!Array.isArray(e))switch(typeof e){case"string":e=[e];break;case"undefined":e=[];break;default:throw new TypeError(`Expected '${t}' to be a string or an array, but got a type of '${typeof e}'`)}return e.filter((e=>{if("string"!=typeof e){if(void 0===e)return!1;throw new TypeError(`Expected '${t}' to be an array of strings, but found a type of '${typeof e}' in the array`)}return!0}))},m=(e,t)=>{t={caseSensitive:!1,...t};const r=e+JSON.stringify(t);if(y.has(r))return y.get(r);const n="!"===e[0];n&&(e=e.slice(1)),e=function(e){if("string"!=typeof e)throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}(e).replace(/\\\*/g,"[\\s\\S]*");const i=new RegExp(`^${e}$`,t.caseSensitive?"":"i");return i.negated=n,y.set(r,i),i};function w(e,t,r){return((e,t,r,n)=>{if(e=d(e,"inputs"),0===(t=d(t,"patterns")).length)return[];t=t.map((e=>m(e,r)));const{allPatterns:i}=r||{},s=[];for(const r of e){let e;const o=[...t].fill(!1);for(const[n,i]of t.entries())if(i.test(r)&&(o[n]=!0,e=!i.negated,!e))break;if(!(!1===e||void 0===e&&t.some((e=>!e.negated))||i&&o.some(((e,r)=>!e&&!t[r].negated)))&&(s.push(r),n))break}return s})(e,t,r,!0).length>0}var b={exports:{}};!function(e){e.exports=function(){var e=Object.prototype.toString;function t(e,t){return null!=e&&Object.prototype.hasOwnProperty.call(e,t)}function r(e){if(!e)return!0;if(s(e)&&0===e.length)return!0;if("string"!=typeof e){for(var r in e)if(t(e,r))return!1;return!0}return!1}function n(t){return e.call(t)}function i(e){return"object"==typeof e&&"[object Object]"===n(e)}var s=Array.isArray||function(t){return"[object Array]"===e.call(t)};function o(e){return"boolean"==typeof e||"[object Boolean]"===n(e)}function a(e){var t=parseInt(e);return t.toString()===e?t:e}function l(e){var n,l,u=function(e){return Object.keys(u).reduce((function(t,r){return"create"===r||"function"==typeof u[r]&&(t[r]=u[r].bind(u,e)),t}),{})};function f(e,t){if(n(e,t))return e[t]}function h(e,t,r,n){if("number"==typeof t&&(t=[t]),!t||0===t.length)return e;if("string"==typeof t)return h(e,t.split(".").map(a),r,n);var i=t[0],s=l(e,i);return 1===t.length?(void 0!==s&&n||(e[i]=r),s):(void 0===s&&(e[i]="number"==typeof t[1]?[]:{}),h(e[i],t.slice(1),r,n))}return n=(e=e||{}).includeInheritedProps?function(){return!0}:function(e,r){return"number"==typeof r&&Array.isArray(e)||t(e,r)},l=e.includeInheritedProps?function(e,t){"string"!=typeof t&&"number"!=typeof t&&(t=String(t));var r=f(e,t);if("__proto__"===t||"prototype"===t||"constructor"===t&&"function"==typeof r)throw new Error("For security reasons, object's magic properties cannot be set");return r}:function(e,t){return f(e,t)},u.has=function(r,n){if("number"==typeof n?n=[n]:"string"==typeof n&&(n=n.split(".")),!n||0===n.length)return!!r;for(var i=0;i<n.length;i++){var o=a(n[i]);if(!("number"==typeof o&&s(r)&&o<r.length||(e.includeInheritedProps?o in Object(r):t(r,o))))return!1;r=r[o]}return!0},u.ensureExists=function(e,t,r){return h(e,t,r,!0)},u.set=function(e,t,r,n){return h(e,t,r,n)},u.insert=function(e,t,r,n){var i=u.get(e,t);n=~~n,s(i)||u.set(e,t,i=[]),i.splice(n,0,r)},u.empty=function(e,t){var a,l;if(!r(t)&&null!=e&&(a=u.get(e,t))){if("string"==typeof a)return u.set(e,t,"");if(o(a))return u.set(e,t,!1);if("number"==typeof a)return u.set(e,t,0);if(s(a))a.length=0;else{if(!i(a))return u.set(e,t,null);for(l in a)n(a,l)&&delete a[l]}}},u.push=function(e,t){var r=u.get(e,t);s(r)||u.set(e,t,r=[]),r.push.apply(r,Array.prototype.slice.call(arguments,2))},u.coalesce=function(e,t,r){for(var n,i=0,s=t.length;i<s;i++)if(void 0!==(n=u.get(e,t[i])))return n;return r},u.get=function(e,t,r){if("number"==typeof t&&(t=[t]),!t||0===t.length)return e;if(null==e)return r;if("string"==typeof t)return u.get(e,t.split("."),r);var n=a(t[0]),i=l(e,n);return void 0===i?r:1===t.length?i:u.get(e[n],t.slice(1),r)},u.del=function(e,t){if("number"==typeof t&&(t=[t]),null==e)return e;if(r(t))return e;if("string"==typeof t)return u.del(e,t.split("."));var i=a(t[0]);return l(e,i),n(e,i)?1!==t.length?u.del(e[i],t.slice(1)):(s(e)?e.splice(i,1):delete e[i],e):e},u}var u=l();return u.create=l,u.withInheritedProps=l({includeInheritedProps:!0}),u}()}(b);var _=b.exports;
|
|
27
27
|
/**
|
|
28
28
|
* @name arrayiffy-if-string
|
|
29
29
|
* @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
|
|
30
|
-
* @version 4.0.
|
|
30
|
+
* @version 4.0.3
|
|
31
31
|
* @author Roy Revelt, Codsen Ltd
|
|
32
32
|
* @license MIT
|
|
33
33
|
* {@link https://codsen.com/os/arrayiffy-if-string/}
|
|
34
|
-
*/function
|
|
34
|
+
*/function T(e){return"string"==typeof e?e.length?[e]:[]:e}
|
|
35
35
|
/**
|
|
36
36
|
* @name string-match-left-right
|
|
37
37
|
* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
|
|
38
|
-
* @version 8.0.
|
|
38
|
+
* @version 8.0.3
|
|
39
39
|
* @author Roy Revelt, Codsen Ltd
|
|
40
40
|
* @license MIT
|
|
41
41
|
* {@link https://codsen.com/os/string-match-left-right/}
|
|
42
|
-
*/function
|
|
42
|
+
*/function v(e){return e&&"object"==typeof e&&!Array.isArray(e)}function O(e){return"string"==typeof e}const A={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},$=e=>e+1;function W(e,t,r,n,i=!1,s=$){const o="function"==typeof r?r():r;if(+t<0&&i&&"EOL"===o)return o;const a={...A,...n};if(t>=e.length&&!i)return!1;let l=i?1:r.length,u=0,f=!1,h=!1,c=!1,g=a.maxMismatches,p=t,y=!1,d=!1,m=!1;function w(){return 1===u&&g<a.maxMismatches-1}for(;e[p];){const t=s(p);if(a.trimBeforeMatching&&""===e[p].trim()){if(!e[t]&&i&&"EOL"===r)return!0;p=s(p);continue}if(a&&!a.i&&a.trimCharsBeforeMatching&&a.trimCharsBeforeMatching.includes(e[p])||a&&a.i&&a.trimCharsBeforeMatching&&a.trimCharsBeforeMatching.map((e=>e.toLowerCase())).includes(e[p].toLowerCase())){if(i&&"EOL"===r&&!e[t])return!0;p=s(p);continue}const n=t>p?r[r.length-l]:r[l-1];if(!a.i&&e[p]===n||a.i&&e[p].toLowerCase()===n.toLowerCase()){if(y||(y=!0),c||(c=!0),l===r.length){if(d=!0,g!==a.maxMismatches)return!1}else 1===l&&(m=!0);if(l-=1,u++,w())return!1;if(!l)return(u!==r.length||g===a.maxMismatches||!f)&&p}else{if(f||u||(f=!0),!(a.maxMismatches&&g&&p))return!(0!==p||1!==l||a.lastMustMatch||!c)&&0;g-=1;for(let n=0;n<=g;n++){const i=t>p?r[r.length-l+1+n]:r[l-2-n],o=e[s(p)];if(i&&(!a.i&&e[p]===i||a.i&&e[p].toLowerCase()===i.toLowerCase())&&(!a.firstMustMatch||l!==r.length)){if(u++,w())return!1;l-=2,y=!0;break}if(o&&i&&(!a.i&&o===i||a.i&&o.toLowerCase()===i.toLowerCase())&&(!a.firstMustMatch||l!==r.length)){if(!u&&!a.hungry)return!1;l-=1,y=!0;break}if(void 0===i&&g>=0&&y&&(!a.firstMustMatch||d)&&(!a.lastMustMatch||m))return p}y||(h=p)}if(!1!==h&&h!==p&&(h=!1),l<1)return p;p=s(p)}return l>0?!(!i||"EOL"!==o)||!!(a&&a.maxMismatches>=l&&c)&&(h||0):void 0}function I(e,t,r,n,i){if(v(i)&&Object.prototype.hasOwnProperty.call(i,"trimBeforeMatching")&&"boolean"!=typeof i.trimBeforeMatching)throw new Error(`string-match-left-right/${e}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(i.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);const s={...A,...i};if("string"==typeof s.trimCharsBeforeMatching&&(s.trimCharsBeforeMatching=T(s.trimCharsBeforeMatching)),s.trimCharsBeforeMatching=s.trimCharsBeforeMatching.map((e=>O(e)?e:String(e))),!O(t))return!1;if(!t.length)return!1;if(!Number.isInteger(r)||r<0)throw new Error(`string-match-left-right/${e}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof r}, equal to:\n${JSON.stringify(r,null,4)}`);let o,a;if(O(n))o=[n];else if(Array.isArray(n))o=n;else if(n){if("function"!=typeof n)throw new Error(`string-match-left-right/${e}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof n}, equal to:\n${JSON.stringify(n,null,4)}`);o=[],o.push(n)}else o=n;if(i&&!v(i))throw new Error(`string-match-left-right/${e}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof i}", and equal to:\n${JSON.stringify(i,null,4)}`);let l=0,u="";if(s&&s.trimCharsBeforeMatching&&s.trimCharsBeforeMatching.some(((e,t)=>e.length>1&&(l=t,u=e,!0))))throw new Error(`string-match-left-right/${e}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${l} is longer than 1 character, ${u.length} (equals to ${u}). Please split it into separate characters and put into array as separate elements.`);if(!o||!Array.isArray(o)||Array.isArray(o)&&!o.length||Array.isArray(o)&&1===o.length&&O(o[0])&&!o[0].trim()){if("function"==typeof s.cb){let n,i=r;if("matchLeftIncl"!==e&&"matchRight"!==e||(i+=1),"L"===e[5])for(let e=i;e--;){const r=t[e];if((!s.trimBeforeMatching||s.trimBeforeMatching&&void 0!==r&&r.trim())&&(!s.trimCharsBeforeMatching||!s.trimCharsBeforeMatching.length||void 0!==r&&!s.trimCharsBeforeMatching.includes(r))){n=e;break}}else if(e.startsWith("matchRight"))for(let e=i;e<t.length;e++){const r=t[e];if((!s.trimBeforeMatching||s.trimBeforeMatching&&r.trim())&&(!s.trimCharsBeforeMatching||!s.trimCharsBeforeMatching.length||!s.trimCharsBeforeMatching.includes(r))){n=e;break}}if(void 0===n)return!1;const o=t[n],a=n+1;let l="";return a&&a>0&&(l=t.slice(0,a)),"L"===e[5]?s.cb(o,l,n):(n&&n>0&&(l=t.slice(n)),s.cb(o,l,n))}let n="";throw i||(n=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${e}(): [THROW_ID_08] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!${n}`)}for(let n=0,i=o.length;n<i;n++){a="function"==typeof o[n];const i=o[n];let l,u,f="",h=r;"matchRight"===e?h+=1:"matchLeft"===e&&(h-=1);const c=W(t,h,i,s,a,(t=>"L"===e[5]?t-1:t+1));if(c&&a&&"function"==typeof i&&"EOL"===i())return!(!i()||s.cb&&!s.cb(l,f,u))&&i();if(Number.isInteger(c)&&(u=e.startsWith("matchLeft")?c-1:c+1,f="L"===e[5]?t.slice(0,c):t.slice(u)),u<0&&(u=void 0),t[u]&&(l=t[u]),Number.isInteger(c)&&(!s.cb||s.cb(l,f,u)))return i}return!1}function j(e,t,r,n){return I("matchLeftIncl",e,t,r,n)}function E(e,t,r,n){return I("matchRightIncl",e,t,r,n)}
|
|
43
43
|
/**
|
|
44
44
|
* @name string-find-heads-tails
|
|
45
45
|
* @fileoverview Finds where are arbitrary templating marker heads and tails located
|
|
46
|
-
* @version 5.0.
|
|
46
|
+
* @version 5.0.3
|
|
47
47
|
* @author Roy Revelt, Codsen Ltd
|
|
48
48
|
* @license MIT
|
|
49
49
|
* {@link https://codsen.com/os/string-find-heads-tails/}
|
|
50
|
-
*/function
|
|
50
|
+
*/function R(e){return"string"==typeof e}const S={fromIndex:0,throwWhenSomethingWrongIsDetected:!0,allowWholeValueToBeOnlyHeadsOrTails:!0,source:"string-find-heads-tails",matchHeadsAndTailsStrictlyInPairsByTheirOrder:!1,relaxedAPI:!1};function N(e,t,r,n){if(n&&(!(i=n)||"object"!=typeof i||Array.isArray(i)))throw new TypeError(`string-find-heads-tails: [THROW_ID_01] the fourth input argument, an Optional Options Object, must be a plain object! Currently it's equal to: ${n} (type: ${typeof n})`);var i;const s={...S,...n};if("string"==typeof s.fromIndex&&/^\d*$/.test(s.fromIndex))s.fromIndex=Number(s.fromIndex);else if(!Number.isInteger(s.fromIndex)||s.fromIndex<0)throw new TypeError(`${s.source} [THROW_ID_18] the fourth input argument must be a natural number or zero! Currently it's: ${s.fromIndex}`);if(!R(e)||0===e.length){if(s.relaxedAPI)return[];throw new TypeError(`string-find-heads-tails: [THROW_ID_02] the first input argument, input string, must be a non-zero-length string! Currently it's: ${typeof e}, equal to: ${e}`)}let o,a;if("string"!=typeof t&&!Array.isArray(t)){if(s.relaxedAPI)return[];throw new TypeError(`string-find-heads-tails: [THROW_ID_03] the second input argument, heads, must be either a string or an array of strings! Currently it's: ${typeof t}, equal to:\n${JSON.stringify(t,null,4)}`)}if("string"==typeof t){if(0===t.length){if(s.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_04] the second input argument, heads, must be a non-empty string! Currently it's empty.")}t=T(t)}else if(Array.isArray(t)){if(0===t.length){if(s.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_05] the second input argument, heads, must be a non-empty array and contain at least one string! Currently it's empty.")}if(t.every(((e,t)=>(o=e,a=t,R(e))))){if(!t.every(((e,t)=>(a=t,R(e)&&e.length>0&&""!==e.trim())))){if(!s.relaxedAPI)throw new TypeError(`string-find-heads-tails: [THROW_ID_07] the second input argument, heads, should not contain empty strings! For example, there's one detected at index ${a} of heads array:\n${JSON.stringify(t,null,4)}.`);if(0===(t=t.filter((e=>R(e)&&e.length>0))).length)return[]}}else{if(!s.relaxedAPI)throw new TypeError(`string-find-heads-tails: [THROW_ID_06] the second input argument, heads, contains non-string elements! For example, element at ${a}th index is ${typeof o}, equal to:\n${JSON.stringify(o,null,4)}. Whole heads array looks like:\n${JSON.stringify(t,null,4)}`);if(0===(t=t.filter((e=>R(e)&&e.length>0))).length)return[]}}if(!R(r)&&!Array.isArray(r)){if(s.relaxedAPI)return[];throw new TypeError(`string-find-heads-tails: [THROW_ID_08] the third input argument, tails, must be either a string or an array of strings! Currently it's: ${typeof r}, equal to:\n${JSON.stringify(r,null,4)}`)}if(R(r)){if(0===r.length){if(s.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_09] the third input argument, tails, must be a non-empty string! Currently it's empty.")}r=T(r)}else if(Array.isArray(r)){if(0===r.length){if(s.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_10] the third input argument, tails, must be a non-empty array and contain at least one string! Currently it's empty.")}if(r.every(((e,t)=>(o=e,a=t,R(e))))){if(!r.every(((e,t)=>(a=t,R(e)&&e.length>0&&""!==e.trim())))){if(!s.relaxedAPI)throw new TypeError(`string-find-heads-tails: [THROW_ID_12] the third input argument, tails, should not contain empty strings! For example, there's one detected at index ${a}. Whole tails array is equal to:\n${JSON.stringify(r,null,4)}`);if(0===(r=r.filter((e=>R(e)&&e.length>0))).length)return[]}}else{if(!s.relaxedAPI)throw new TypeError(`string-find-heads-tails: [THROW_ID_11] the third input argument, tails, contains non-string elements! For example, element at ${a}th index is ${typeof o}, equal to:\n${JSON.stringify(o,null,4)}. Whole tails array is equal to:\n${JSON.stringify(r,null,4)}`);if(0===(r=r.filter((e=>R(e)&&e.length>0))).length)return[]}}const l=s.source===S.source;if(s.throwWhenSomethingWrongIsDetected&&!s.allowWholeValueToBeOnlyHeadsOrTails){if(T(t).includes(e))throw new Error(`${s.source}${l?": [THROW_ID_16]":""} the whole input string can't be equal to ${R(t)?"":"one of "}heads (${e})!`);if(T(r).includes(e))throw new Error(`${s.source}${l?": [THROW_ID_17]":""} the whole input string can't be equal to ${R(r)?"":"one of "}tails (${e})!`)}const u=t.concat(r).map((e=>e.charAt(0))).reduce(((e,t)=>t.charCodeAt(0)>e[1]?[e[0],t.charCodeAt(0)]:t.charCodeAt(0)<e[0]?[t.charCodeAt(0),e[1]]:e),[t[0].charCodeAt(0),t[0].charCodeAt(0)]),f=[];let h,c=!1,g={},p="";for(let n=s.fromIndex,i=e.length;n<i;n++){const o=e[n].charCodeAt(0);if(o<=u[1]&&o>=u[0]){const o=E(e,n,t);if(o&&s.matchHeadsAndTailsStrictlyInPairsByTheirOrder)for(let e=t.length;e--;)if(t[e]===o){h=e;break}if("string"==typeof o){if(!c){g={},g.headsStartAt=n,g.headsEndAt=n+o.length,c=!0,n+=o.length-1,p&&(p="");continue}if(s.throwWhenSomethingWrongIsDetected)throw new TypeError(`${s.source}${l?": [THROW_ID_19]":""} When processing "${e}", we found heads (${e.slice(n,n+o.length)}) starting at character with index number "${n}" and there was another set of heads before it! Generally speaking, there should be "heads-tails-heads-tails", not "heads-heads-tails"!\nWe're talking about the area of the code:\n\n\n--------------------------------------starts\n${e.slice(Math.max(n-200,0),n)}\n [33m-------\x3e[39m [31m${e.slice(n,n+o.length)}[39m [33m<-------[39m\n${e.slice(n+o.length,Math.min(i,n+200))}\n--------------------------------------ends\n\n\nTo turn off this error being thrown, set opts.throwWhenSomethingWrongIsDetected to Boolean false.`)}const a=E(e,n,r);if(c&&a&&s.matchHeadsAndTailsStrictlyInPairsByTheirOrder&&void 0!==h&&void 0!==r[h]&&r[h]!==a){let n;for(let e=r.length;e--;)if(r[e]===a){n=e;break}throw new TypeError(`${s.source}${l?": [THROW_ID_20]":""} When processing "${e}", we had "opts.matchHeadsAndTailsStrictlyInPairsByTheirOrder" on. We found heads (${t[h]}) but the tails the followed it were not of the same index, ${h} (${r[h]}) but ${n} (${a}).`)}if("string"==typeof a){if(c){g.tailsStartAt=n,g.tailsEndAt=n+a.length,f.push(g),g={},c=!1,n+=a.length-1;continue}s.throwWhenSomethingWrongIsDetected&&(p=`${s.source}${l?": [THROW_ID_21]":""} When processing "${e}", we found tails (${e.slice(n,n+a.length)}) starting at character with index number "${n}" but there were no heads preceding it. That's very naughty!`)}}if(s.throwWhenSomethingWrongIsDetected&&n===i-1){if(0!==Object.keys(g).length)throw new TypeError(`${s.source}${l?": [THROW_ID_22]":""} When processing "${e}", we reached the end of the string and yet didn't find any tails (${JSON.stringify(r,null,4)}) to match the last detected heads (${e.slice(g.headsStartAt,g.headsEndAt)})!`);if(p)throw new Error(p)}}return f}
|
|
51
51
|
/**
|
|
52
52
|
* @name ast-get-values-by-key
|
|
53
53
|
* @fileoverview Extract values and paths from AST by keys OR set them by keys
|
|
54
|
-
* @version 4.0.
|
|
54
|
+
* @version 4.0.3
|
|
55
55
|
* @author Roy Revelt, Codsen Ltd
|
|
56
56
|
* @license MIT
|
|
57
57
|
* {@link https://codsen.com/os/ast-get-values-by-key/}
|
|
58
|
-
*/function
|
|
58
|
+
*/function H(e,t,r){let i;void 0!==r&&(i=Array.isArray(r)?n(r):[n(r)]);const s=[],o=p(e,((e,r,n)=>{const o=void 0!==r?r:e;if(void 0!==r&&w(e,t,{caseSensitive:!0}))if(void 0===i)s.push({val:r,path:n.path});else if(i.length)return i.shift();return o}));return void 0===i?s:o}
|
|
59
59
|
/**
|
|
60
60
|
* @name string-collapse-leading-whitespace
|
|
61
61
|
* @fileoverview Collapse the leading and trailing whitespace of a string
|
|
62
|
-
* @version 6.0.
|
|
62
|
+
* @version 6.0.3
|
|
63
63
|
* @author Roy Revelt, Codsen Ltd
|
|
64
64
|
* @license MIT
|
|
65
65
|
* {@link https://codsen.com/os/string-collapse-leading-whitespace/}
|
|
66
|
-
*/function
|
|
66
|
+
*/function D(e,t=1){function r(e){return Array.from(e).reverse().join("")}function n(e,t,r){const n=r?"\n":"\r",i=r?"\r":"\n";if(!e)return e;let s=0,o="";for(let r=0,a=e.length;r<a;r++)(e[r]===n||e[r]===i&&e[r-1]!==n)&&s++,"\r\n".includes(e[r])||" "===e[r]?" "===e[r]?o+=e[r]:e[r]===n?s<=t&&(o+=e[r],e[r+1]===i&&(o+=e[r+1],r++)):e[r]===i&&(!e[r-1]||e[r-1]!==n)&&s<=t&&(o+=e[r]):e[r+1]||s||(o+=" ");return o}if("string"==typeof e&&e.length){let i=1;"number"==typeof+t&&Number.isInteger(+t)&&+t>=0&&(i=+t);let s="",o="";if(e.trim()){if(!e[0].trim())for(let t=0,r=e.length;t<r;t++)if(e[t].trim()){s=e.slice(0,t);break}}else s=e;if(e.trim()&&(""===e.slice(-1).trim()||" "===e.slice(-1)))for(let t=e.length;t--;)if(e[t].trim()){o=e.slice(t+1);break}return`${n(s,i,!1)}${e.trim()}${r(n(r(o),i,!0))}`}return e}
|
|
67
67
|
/**
|
|
68
68
|
* @name ranges-push
|
|
69
69
|
* @fileoverview Gather string index ranges
|
|
70
|
-
* @version 6.0.
|
|
70
|
+
* @version 6.0.3
|
|
71
71
|
* @author Roy Revelt, Codsen Ltd
|
|
72
72
|
* @license MIT
|
|
73
73
|
* {@link https://codsen.com/os/ranges-push/}
|
|
74
|
-
*/const
|
|
74
|
+
*/const x={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function M(e,t){if(!Array.isArray(e)||!e.length)return e;const r={...x,...t};let n,i;if(r.strictlyTwoElementsInRangeArrays&&!e.filter((e=>e)).every(((e,t)=>2===e.length||(n=t,i=e.length,!1))))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 ${i} elements!`);if(!e.filter((e=>e)).every(((e,t)=>!(!Number.isInteger(e[0])||e[0]<0||!Number.isInteger(e[1])||e[1]<0)||(n=t,!1))))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!`);const s=e.filter((e=>e)).length**2;let o=0;return Array.from(e).filter((e=>e)).sort(((e,t)=>(r.progressFn&&(o+=1,r.progressFn(Math.floor(100*o/s))),e[0]===t[0]?e[1]<t[1]?-1:e[1]>t[1]?1:0:e[0]<t[0]?-1:1)))}const C={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function B(e){return null!=e}function F(e){return Number.isInteger(e)&&e>=0}function k(e){return"string"==typeof e}const J={limitToBeAddedWhitespace:!1,limitLinebreaksCount:1,mergeType:1};class P{constructor(e){const t={...J,...e};if(t.mergeType&&1!==t.mergeType&&2!==t.mergeType)if(k(t.mergeType)&&"1"===t.mergeType.trim())t.mergeType=1;else{if(!k(t.mergeType)||"2"!==t.mergeType.trim())throw new Error(`ranges-push: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof t.mergeType}", equal to ${JSON.stringify(t.mergeType,null,4)}`);t.mergeType=2}this.opts=t,this.ranges=[]}ranges;opts;add(e,t,r){if(null==e&&null==t)return;if(B(e)&&!B(t)){if(Array.isArray(e)){if(e.length){if(e.some((e=>Array.isArray(e))))return void e.forEach((e=>{Array.isArray(e)&&this.add(...e)}));e.length&&F(+e[0])&&F(+e[1])&&this.add(...e)}return}throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_12] the first input argument, "from" is set (${JSON.stringify(e,null,0)}) but second-one, "to" is not (${JSON.stringify(t,null,0)})`)}if(!B(e)&&B(t))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_13] the second input argument, "to" is set (${JSON.stringify(t,null,0)}) but first-one, "from" is not (${JSON.stringify(e,null,0)})`);const n=+e,i=+t;if(F(r)&&(r=String(r)),!F(n)||!F(i))throw F(n)&&n>=0?new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof i}" equal to: ${JSON.stringify(i,null,4)}`):new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof n}" equal to: ${JSON.stringify(n,null,4)}`);if(B(r)&&!k(r)&&!F(r))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_08] The third argument, the value to add, was given not as string but ${typeof r}, equal to:\n${JSON.stringify(r,null,4)}`);if(B(this.ranges)&&Array.isArray(this.last())&&n===this.last()[1]){if(this.last()[1]=i,this.last(),null!==this.last()[2]&&B(r)){let e=!(this.last()[2]&&this.last()[2].length>0)||this.opts&&this.opts.mergeType&&1!==this.opts.mergeType?r:this.last()[2]+r;this.opts.limitToBeAddedWhitespace&&(e=D(e,this.opts.limitLinebreaksCount)),k(e)&&!e.length||(this.last()[2]=e)}}else{this.ranges||(this.ranges=[]);const e=void 0===r||k(r)&&!r.length?[n,i]:[n,i,r&&this.opts.limitToBeAddedWhitespace?D(r,this.opts.limitLinebreaksCount):r];this.ranges.push(e)}}push(e,t,r){this.add(e,t,r)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=function(e,t){function r(e){return e&&"object"==typeof e&&!Array.isArray(e)}if(!Array.isArray(e)||!e.length)return null;let n;if(t){if(!r(t))throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:\n${JSON.stringify(t,null,4)} (type ${typeof t})`);if(n={...C,...t},n.progressFn&&r(n.progressFn)&&!Object.keys(n.progressFn).length)n.progressFn=null;else if(n.progressFn&&"function"!=typeof n.progressFn)throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof n.progressFn}", equal to ${JSON.stringify(n.progressFn,null,4)}`);if(n.mergeType&&1!=+n.mergeType&&2!=+n.mergeType)throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof n.mergeType}", equal to ${JSON.stringify(n.mergeType,null,4)}`);if("boolean"!=typeof n.joinRangesThatTouchEdges)throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof n.joinRangesThatTouchEdges}", equal to ${JSON.stringify(n.joinRangesThatTouchEdges,null,4)}`)}else n={...C};const i=e.filter((e=>e)).map((e=>[...e])).filter((e=>void 0!==e[2]||e[0]!==e[1]));let s,o,a;if(s=n.progressFn?M(i,{progressFn:e=>{a=Math.floor(e/5),a!==o&&(o=a,n.progressFn(a))}}):M(i),!s)return null;const l=s.length-1;for(let e=l;e>0;e--)n.progressFn&&(a=Math.floor(78*(1-e/l))+21,a!==o&&a>o&&(o=a,n.progressFn(a))),(s[e][0]<=s[e-1][0]||!n.joinRangesThatTouchEdges&&s[e][0]<s[e-1][1]||n.joinRangesThatTouchEdges&&s[e][0]<=s[e-1][1])&&(s[e-1][0]=Math.min(s[e][0],s[e-1][0]),s[e-1][1]=Math.max(s[e][1],s[e-1][1]),void 0!==s[e][2]&&(s[e-1][0]>=s[e][0]||s[e-1][1]<=s[e][1])&&null!==s[e-1][2]&&(null===s[e][2]&&null!==s[e-1][2]?s[e-1][2]=null:null!=s[e-1][2]?2==+n.mergeType&&s[e-1][0]===s[e][0]?s[e-1][2]=s[e][2]:s[e-1][2]+=s[e][2]:s[e-1][2]=s[e][2]),s.splice(e,1),e=s.length);return s.length?s:null}(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map((e=>B(e[2])?[e[0],e[1],D(e[2],this.opts.limitLinebreaksCount)]:e)):this.ranges):null}wipe(){this.ranges=[]}replace(e){if(Array.isArray(e)&&e.length){if(!Array.isArray(e[0])||!F(e[0][0]))throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(e[0],null,4)} should be an array and its first element should be an integer, a string index.`);this.ranges=Array.from(e)}else this.ranges=[]}last(){return Array.isArray(this.ranges)&&this.ranges.length?this.ranges[this.ranges.length-1]:null}}
|
|
75
75
|
/**
|
|
76
76
|
* @name ranges-sort
|
|
77
77
|
* @fileoverview Sort string index ranges
|
|
78
|
-
* @version 5.0.
|
|
78
|
+
* @version 5.0.3
|
|
79
79
|
* @author Roy Revelt, Codsen Ltd
|
|
80
80
|
* @license MIT
|
|
81
81
|
* {@link https://codsen.com/os/ranges-sort/}
|
|
82
|
-
*/const
|
|
82
|
+
*/const V={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function q(e,t){if(!Array.isArray(e)||!e.length)return e;const r={...V,...t};let n,i;if(r.strictlyTwoElementsInRangeArrays&&!e.filter((e=>e)).every(((e,t)=>2===e.length||(n=t,i=e.length,!1))))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 ${i} elements!`);if(!e.filter((e=>e)).every(((e,t)=>!(!Number.isInteger(e[0])||e[0]<0||!Number.isInteger(e[1])||e[1]<0)||(n=t,!1))))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!`);const s=e.filter((e=>e)).length**2;let o=0;return Array.from(e).filter((e=>e)).sort(((e,t)=>(r.progressFn&&(o+=1,r.progressFn(Math.floor(100*o/s))),e[0]===t[0]?e[1]<t[1]?-1:e[1]>t[1]?1:0:e[0]<t[0]?-1:1)))}
|
|
83
83
|
/**
|
|
84
84
|
* @name ranges-merge
|
|
85
85
|
* @fileoverview Merge and sort string index ranges
|
|
86
|
-
* @version 8.0.
|
|
86
|
+
* @version 8.0.3
|
|
87
87
|
* @author Roy Revelt, Codsen Ltd
|
|
88
88
|
* @license MIT
|
|
89
89
|
* {@link https://codsen.com/os/ranges-merge/}
|
|
90
|
-
*/const
|
|
90
|
+
*/const L={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function U(e,t){function r(e){return e&&"object"==typeof e&&!Array.isArray(e)}if(!Array.isArray(e)||!e.length)return null;let n;if(t){if(!r(t))throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:\n${JSON.stringify(t,null,4)} (type ${typeof t})`);if(n={...L,...t},n.progressFn&&r(n.progressFn)&&!Object.keys(n.progressFn).length)n.progressFn=null;else if(n.progressFn&&"function"!=typeof n.progressFn)throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof n.progressFn}", equal to ${JSON.stringify(n.progressFn,null,4)}`);if(n.mergeType&&1!=+n.mergeType&&2!=+n.mergeType)throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof n.mergeType}", equal to ${JSON.stringify(n.mergeType,null,4)}`);if("boolean"!=typeof n.joinRangesThatTouchEdges)throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof n.joinRangesThatTouchEdges}", equal to ${JSON.stringify(n.joinRangesThatTouchEdges,null,4)}`)}else n={...L};const i=e.filter((e=>e)).map((e=>[...e])).filter((e=>void 0!==e[2]||e[0]!==e[1]));let s,o,a;if(s=n.progressFn?q(i,{progressFn:e=>{a=Math.floor(e/5),a!==o&&(o=a,n.progressFn(a))}}):q(i),!s)return null;const l=s.length-1;for(let e=l;e>0;e--)n.progressFn&&(a=Math.floor(78*(1-e/l))+21,a!==o&&a>o&&(o=a,n.progressFn(a))),(s[e][0]<=s[e-1][0]||!n.joinRangesThatTouchEdges&&s[e][0]<s[e-1][1]||n.joinRangesThatTouchEdges&&s[e][0]<=s[e-1][1])&&(s[e-1][0]=Math.min(s[e][0],s[e-1][0]),s[e-1][1]=Math.max(s[e][1],s[e-1][1]),void 0!==s[e][2]&&(s[e-1][0]>=s[e][0]||s[e-1][1]<=s[e][1])&&null!==s[e-1][2]&&(null===s[e][2]&&null!==s[e-1][2]?s[e-1][2]=null:null!=s[e-1][2]?2==+n.mergeType&&s[e-1][0]===s[e][0]?s[e-1][2]=s[e][2]:s[e-1][2]+=s[e][2]:s[e-1][2]=s[e][2]),s.splice(e,1),e=s.length);return s.length?s:null}
|
|
91
91
|
/**
|
|
92
92
|
* @name ranges-apply
|
|
93
93
|
* @fileoverview Take an array of string index ranges, delete/replace the string according to them
|
|
94
|
-
* @version 6.0.
|
|
94
|
+
* @version 6.0.3
|
|
95
95
|
* @author Roy Revelt, Codsen Ltd
|
|
96
96
|
* @license MIT
|
|
97
97
|
* {@link https://codsen.com/os/ranges-apply/}
|
|
98
|
-
*/function
|
|
98
|
+
*/function z(e,t,r){let n,i=0,s=0;if(0===arguments.length)throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");if("string"!=typeof e)throw new TypeError(`ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(t&&!Array.isArray(t))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof t}, equal to: ${JSON.stringify(t,null,4)}`);if(r&&"function"!=typeof r)throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(!t||!t.filter((e=>e)).length)return e;n=Array.isArray(t)&&Number.isInteger(t[0])&&Number.isInteger(t[1])?[Array.from(t)]:Array.from(t);const o=n.length;let a=0;n.filter((e=>e)).forEach(((e,t)=>{if(r&&(i=Math.floor(a/o*10),i!==s&&(s=i,r(i))),!Array.isArray(e))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${t}th element not an array: ${JSON.stringify(e,null,4)}, which is ${typeof e}`);if(!Number.isInteger(e[0])){if(!Number.isInteger(+e[0])||+e[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${t}th element, array ${JSON.stringify(e,null,0)}. Its first element is not an integer, string index, but ${typeof e[0]}, equal to: ${JSON.stringify(e[0],null,4)}.`);n[t][0]=+n[t][0]}if(!Number.isInteger(e[1])){if(!Number.isInteger(+e[1])||+e[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${t}th element, array ${JSON.stringify(e,null,0)}. Its second element is not an integer, string index, but ${typeof e[1]}, equal to: ${JSON.stringify(e[1],null,4)}.`);n[t][1]=+n[t][1]}a+=1}));const l=U(n,{progressFn:e=>{r&&(i=10+Math.floor(e/10),i!==s&&(s=i,r(i)))}}),u=Array.isArray(l)?l.length:0;if(u>0){const t=e.slice(l[u-1][1]);e=l.reduce(((t,n,o,a)=>{r&&(i=20+Math.floor(o/u*80),i!==s&&(s=i,r(i)));return t+e.slice(0===o?0:a[o-1][1],a[o][0])+(a[o][2]||"")}),""),e+=t}return e}
|
|
99
99
|
/**
|
|
100
100
|
* @name string-trim-spaces-only
|
|
101
101
|
* @fileoverview Like String.trim() but you can choose granularly what to trim
|
|
102
|
-
* @version 4.0.
|
|
102
|
+
* @version 4.0.3
|
|
103
103
|
* @author Roy Revelt, Codsen Ltd
|
|
104
104
|
* @license MIT
|
|
105
105
|
* {@link https://codsen.com/os/string-trim-spaces-only/}
|
|
106
|
-
*/const
|
|
106
|
+
*/const G={classicTrim:!1,cr:!1,lf:!1,tab:!1,space:!0,nbsp:!1};function K(e,t){if("string"!=typeof e)throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof e}, equal to:\n${JSON.stringify(e,null,4)}`);const r={...G,...t};function n(e){return r.classicTrim&&!e.trim()||!r.classicTrim&&(r.space&&" "===e||r.cr&&"\r"===e||r.lf&&"\n"===e||r.tab&&"\t"===e||r.nbsp&&" "===e)}let i,s;if(e.length){if(n(e[0]))for(let t=0,r=e.length;t<r;t++){if(!n(e[t])){i=t;break}if(t===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(n(e[e.length-1]))for(let t=e.length;t--;)if(!n(e[t])){s=t+1;break}return i?s?{res:e.slice(i,s),ranges:[[0,i],[s,e.length]]}:{res:e.slice(i),ranges:[[0,i]]}:s?{res:e.slice(0,s),ranges:[[s,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}}
|
|
107
107
|
/**
|
|
108
108
|
* @name string-remove-duplicate-heads-tails
|
|
109
109
|
* @fileoverview Detect and (recursively) remove head and tail wrappings around the input string
|
|
110
|
-
* @version 6.0.
|
|
110
|
+
* @version 6.0.3
|
|
111
111
|
* @author Roy Revelt, Codsen Ltd
|
|
112
112
|
* @license MIT
|
|
113
113
|
* {@link https://codsen.com/os/string-remove-duplicate-heads-tails/}
|
|
114
|
-
*/const Y=Object.prototype.hasOwnProperty,Z={heads:"%%_",tails:"_%%",headsNoWrap:"%%-",tailsNoWrap:"-%%",lookForDataContainers:!0,dataContainerIdentifierTails:"_data",wrapHeadsWith:"",wrapTailsWith:"",dontWrapVars:[],preventDoubleWrapping:!0,wrapGlobalFlipSwitch:!0,noSingleMarkers:!1,resolveToBoolIfAnyValuesContainBool:!0,resolveToFalseIfAnyValuesContainBool:!0,throwWhenNonStringInsertedInString:!1,allowUnresolved:!1};function ee(e){return"string"==typeof e}function te(e){return"boolean"==typeof e}function re(e){return null===e}function ne(e){return e&&"object"==typeof e&&!Array.isArray(e)}function ie(e){return null!=e}function se(e){return ee(e)?e.trim():e}function oe(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=0,r=e.length;t<r;t++)if("."===e[t])return e.slice(t+1);return e}function ae(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=e.length;t--;)if("."===e[t])return e.slice(0,t);return e}function le(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=e.length;t--;)if("."===e[t])return e.slice(t+1);return e}function ue(e,t){return!("string"!=typeof e||!e.trim())&&!!(e.includes(t.heads)||e.includes(t.tails)||ee(t.headsNoWrap)&&t.headsNoWrap.length>0&&e.includes(t.headsNoWrap)||ee(t.tailsNoWrap)&&t.tailsNoWrap.length>0&&e.includes(t.tailsNoWrap))}function fe(e,t,r=!1,n,i,s){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),ee(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some((e=>_.isMatch(s,e)))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&ee(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return t.wrapHeadsWith+e+t.wrapTailsWith;if(r){if(!ee(e))return e;const r=function(e,t){const r=Object.prototype.hasOwnProperty;if(void 0===e)throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_01] The input is missing!");if("string"!=typeof e)return e;if(t&&!c(t))throw new Error(`string-remove-duplicate-heads-tails: [THROW_ID_03] The given options are not a plain object but ${typeof t}!`);const n={...t};if(n&&r.call(n,"heads")){if(!O(n.heads).every((e=>"string"==typeof e||Array.isArray(e))))throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The opts.heads contains elements which are not string-type!");"string"==typeof n.heads&&(n.heads=O(n.heads))}if(n&&r.call(n,"tails")){if(!O(n.tails).every((e=>"string"==typeof e||Array.isArray(e))))throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The opts.tails contains elements which are not string-type!");"string"==typeof n.tails&&(n.tails=O(n.tails))}const i=X(e).res;if(0===i.length)return e;e=i;const s={heads:["{{"],tails:["}}"],...n};s.heads=s.heads.map((e=>e.trim())),s.tails=s.tails.map((e=>e.trim()));let o=!1,a=!1;const l=new q({limitToBeAddedWhitespace:!0}),u=new q({limitToBeAddedWhitespace:!0});let f=!0,h=!0,g="";function p(e,t){let r;return S(e,0,t.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&S(e,r,t.tails,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})?e.slice(r):e}for(;e!==p(e,s);)e=X(p(e,s)).res;function y(e,t){let r;return R(e,e.length-1,t.tails,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&r&&R(e,r,t.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})?e.slice(0,r+1):e}for(;e!==y(e,s);)e=X(y(e,s)).res;if(!(s.heads.length&&S(e,0,s.heads,{trimBeforeMatching:!0})&&s.tails.length&&R(e,e.length-1,s.tails,{trimBeforeMatching:!0})))return X(e).res;for(let t=0,r=e.length;t<r;t++)if(""===e[t].trim());else{let r;if(S(e,t,s.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&r){let n;h=!0,f&&(f=!0),S(e,r,s.tails,{trimBeforeMatching:!0,cb:(e,t,r)=>(n=r,!0)})&&l.push(t,n),u.current()&&o&&"tails"!==g&&l.push(u.current()),o||u.current()&&(l.push(u.current()),u.wipe()),u.push(t,r),g="heads",t=r-1;continue}if(S(e,t,s.tails,{trimBeforeMatching:!0,cb:(t,n,i)=>(r=Number.isInteger(i)?i:e.length,!0)})&&r){h=!0,f?("heads"===g&&u.wipe(),f=!1):u.push(t,r),g="tails",t=r-1;continue}f&&(f=!0),h&&!o?(o=!0,h=!1):h&&!a?(a=!0,f=!0,h=!1,"heads"===g&&u.wipe()):h&&a&&u.wipe()}return u.current()&&l.push(u.current()),l.current()?K(e,l.current()).trim():e.trim()}(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return ee(r)?function(e,t,r){let n,i;return"string"==typeof e&&e.length>0&&S(e,0,t,{trimBeforeMatching:!0,cb:(e,t,r)=>(n=r,!0)})&&R(e,e.length-1,r,{trimBeforeMatching:!0,cb:(e,t,r)=>(i=r+1,!0)})?e.slice(n,i):e}(r,t.wrapHeadsWith,t.wrapTailsWith):r}return e}function he(e,t,r,n){let i;if(-1!==r.indexOf(".")){let s=r,o=!0;if(n.lookForDataContainers&&"string"==typeof n.dataContainerIdentifierTails&&n.dataContainerIdentifierTails.length>0&&!s.endsWith(n.dataContainerIdentifierTails)){const r=v.get(e,s+n.dataContainerIdentifierTails);ne(r)&&v.get(r,t)&&(i=v.get(r,t),o=!1)}for(;o&&-1!==s.indexOf(".");){if(s=ae(s),le(s)===t)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop. The parent key "${le(s)}" is called the same as the variable "${t}" we're looking for.`);if(n.lookForDataContainers&&"string"==typeof n.dataContainerIdentifierTails&&n.dataContainerIdentifierTails.length>0&&!s.endsWith(n.dataContainerIdentifierTails)){const r=v.get(e,s+n.dataContainerIdentifierTails);ne(r)&&v.get(r,t)&&(i=v.get(r,t),o=!1)}if(void 0===i){const r=v.get(e,s);ne(r)&&v.get(r,t)&&(i=v.get(r,t),o=!1)}}}if(void 0===i){const r=v.get(e,t);void 0!==r&&(i=r)}if(void 0===i)if(-1===t.indexOf(".")){const n=x(e,t);if(n.length>0)for(let e=0,s=n.length;e<s;e++){if(ee(n[e].val)||te(n[e].val)||re(n[e].val)){i=n[e].val;break}if("number"==typeof n[e].val){i=String(n[e].val);break}if(Array.isArray(n[e].val)){i=n[e].val.join("");break}throw new Error(`json-variables/findValues(): [THROW_ID_21] While trying to resolve: "${t}" at path "${r}", we actually found the key named ${t}, but it was not equal to a string but to:\n${JSON.stringify(n[e],null,4)}\nWe can't resolve a string with that! It should be a string.`)}}else{const r=x(e,function(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=0,r=e.length;t<r;t++)if("."===e[t])return e.slice(0,t);return e}(t));if(r.length>0)for(let e=0,n=r.length;e<n;e++){const n=v.get(r[e].val,oe(t));n&&ee(n)&&(i=n)}}return i}function ce(e,t,r,n,i=[]){if(i.includes(r)){let e="";if(i.length>1){const t=" →\n";e=i.reduce(((e,n,i)=>e+(0===i?"":t)+(n===r?"💥 ":" ")+n)," Here's the path we travelled up until we hit the recursion:\n\n"),e+=`${t}💥 ${r}`}throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop, the key is referencing itself."${e}`)}const s={},o=Array.from(i);o.push(r);const a=new q;function l(i,l,u){for(let f=0,h=i.length;f<h;f++){const h=i[f],c=t.slice(h.headsEndAt,h.tailsStartAt);if(0===c.length)a.push(h.headsStartAt,h.tailsEndAt);else if(Y.call(s,c)&&ee(s[c]))a.push(h.headsStartAt,h.tailsEndAt,s[c]);else{let i=he(e,c.trim(),r,n);if(void 0===i)if(!0===n.allowUnresolved)i="";else{if("string"!=typeof n.allowUnresolved)throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${t.slice(h.headsEndAt,h.tailsStartAt)}. We're at path: "${r}".`);i=n.allowUnresolved}if(!u&&n.throwWhenNonStringInsertedInString&&!ee(i))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${t.slice(h.headsEndAt,h.tailsStartAt)} at path ${r}, it resolved into a non-string value, ${JSON.stringify(i,null,4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);if(te(i)){if(n.resolveToBoolIfAnyValuesContainBool)return a.wipe(),!n.resolveToFalseIfAnyValuesContainBool&&i;i=""}else{if(re(i)&&u)return a.wipe(),i;i=Array.isArray(i)?String(i.join("")):re(i)?"":String(i)}const f=r.includes(".")?`${ae(r)}.${c}`:c;if(ue(i,n)){const t=fe(ce(e,i,f,n,o),n,l,0,0,c.trim());ee(t)&&a.push(h.headsStartAt,h.tailsEndAt,t)}else{s[c]=i;const e=fe(i,n,l,0,0,c.trim());ee(e)&&a.push(h.headsStartAt,h.tailsEndAt,e)}}}}let u;try{u=D(t,n.heads,n.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(e){throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${t}" at path ${r}, something wrong with heads and tails was detected! Here's the internal error message:\n${e}`)}let f=!1;1===u.length&&""===K(t,[[u[0].headsStartAt,u[0].tailsEndAt]]).trim()&&(f=!0);const h=l(u,!1,f);if(te(h))return h;if(re(h))return h;try{u=D(t,n.headsNoWrap,n.tailsNoWrap,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(e){throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${t}" at path ${r}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:\n${e}`)}1===u.length&&""===K(t,[[u[0].headsStartAt,u[0].tailsEndAt]]).trim()&&(f=!0);const c=l(u,!0,f);return te(c)||re(c)?c:a&&a.current()?K(t,a.current()):t}e.defaults=Z,e.jVar=function(e,t){if(!arguments.length)throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");if(!ne(e))throw new TypeError("json-variables/jVar(): [THROW_ID_02] Alas! The input must be a plain object! Currently it's: "+(Array.isArray(e)?"array":typeof e));if(t&&!ne(t))throw new TypeError("json-variables/jVar(): [THROW_ID_03] Alas! An Optional Options Object must be a plain object! Currently it's: "+(Array.isArray(t)?"array":typeof t));const r={...Z,...t};let n,i,s;if(r.dontWrapVars?Array.isArray(r.dontWrapVars)||(r.dontWrapVars=O(r.dontWrapVars)):r.dontWrapVars=[],r.dontWrapVars.length>0&&!r.dontWrapVars.every(((e,t)=>!!ee(e)||(n=e,i=t,!1))))throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in opts.dontWrapVars should be of a string type. Computer detected a value "${n}" at index ${i}, which is not string but ${Array.isArray(n)?"array":typeof n}!`);if(""===r.heads)throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");if(""===r.tails)throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");if(r.lookForDataContainers&&""===r.dataContainerIdentifierTails)throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");if(r.heads===r.tails)throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");if(r.heads===r.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");if(r.tails===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");if(""===r.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");if(""===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");if(r.headsNoWrap===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");return p(e,((t,n,i)=>{if(ie(n)&&ue(t,r))throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!\nPlease check the following key: ${t}`);if(s=void 0!==n?n:t,""===s)return s;if(0!==r.heads.length&&se(s)===se(r.heads)||0!==r.tails.length&&se(s)===se(r.tails)||0!==r.headsNoWrap.length&&se(s)===se(r.headsNoWrap)||0!==r.tailsNoWrap.length&&se(s)===se(r.tailsNoWrap)){if(!r.noSingleMarkers)return s;throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${se(s)} which is equal to ${se(s)===se(r.heads)?"heads":""}${se(s)===se(r.tails)?"tails":""}${ee(r.headsNoWrap)&&se(s)===se(r.headsNoWrap)?"headsNoWrap":""}${ee(r.tailsNoWrap)&&se(s)===se(r.tailsNoWrap)?"tailsNoWrap":""}. If you wouldn't have set opts.noSingleMarkers to "true" this error would not happen and computer would have left the current element (${se(s)}) alone`)}return ee(s)&&ue(s,r)?ce(e,s,i.path,r):s}))},e.version="11.0.2",Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
114
|
+
*/const Q=Object.prototype.hasOwnProperty,X={heads:"%%_",tails:"_%%",headsNoWrap:"%%-",tailsNoWrap:"-%%",lookForDataContainers:!0,dataContainerIdentifierTails:"_data",wrapHeadsWith:"",wrapTailsWith:"",dontWrapVars:[],preventDoubleWrapping:!0,wrapGlobalFlipSwitch:!0,noSingleMarkers:!1,resolveToBoolIfAnyValuesContainBool:!0,resolveToFalseIfAnyValuesContainBool:!0,throwWhenNonStringInsertedInString:!1,allowUnresolved:!1};function Y(e){return"string"==typeof e}function Z(e){return"boolean"==typeof e}function ee(e){return null===e}function te(e){return e&&"object"==typeof e&&!Array.isArray(e)}function re(e){return null!=e}function ne(e){return Y(e)?e.trim():e}function ie(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=0,r=e.length;t<r;t++)if("."===e[t])return e.slice(t+1);return e}function se(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=e.length;t--;)if("."===e[t])return e.slice(0,t);return e}function oe(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=e.length;t--;)if("."===e[t])return e.slice(t+1);return e}function ae(e,t){return!("string"!=typeof e||!e.trim())&&!!(e.includes(t.heads)||e.includes(t.tails)||Y(t.headsNoWrap)&&t.headsNoWrap.length>0&&e.includes(t.headsNoWrap)||Y(t.tailsNoWrap)&&t.tailsNoWrap.length>0&&e.includes(t.tailsNoWrap))}function le(e,t,r=!1,n,i,s){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),Y(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some((e=>w(s,e)))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&Y(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return t.wrapHeadsWith+e+t.wrapTailsWith;if(r){if(!Y(e))return e;const r=function(e,t){const r=Object.prototype.hasOwnProperty;if(void 0===e)throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_01] The input is missing!");if("string"!=typeof e)return e;if(t&&!c(t))throw new Error(`string-remove-duplicate-heads-tails: [THROW_ID_03] The given options are not a plain object but ${typeof t}!`);const n={...t};if(n&&r.call(n,"heads")){if(!T(n.heads).every((e=>"string"==typeof e||Array.isArray(e))))throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The opts.heads contains elements which are not string-type!");"string"==typeof n.heads&&(n.heads=T(n.heads))}if(n&&r.call(n,"tails")){if(!T(n.tails).every((e=>"string"==typeof e||Array.isArray(e))))throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The opts.tails contains elements which are not string-type!");"string"==typeof n.tails&&(n.tails=T(n.tails))}const i=K(e).res;if(0===i.length)return e;e=i;const s={heads:["{{"],tails:["}}"],...n};s.heads=s.heads.map((e=>e.trim())),s.tails=s.tails.map((e=>e.trim()));let o=!1,a=!1;const l=new P({limitToBeAddedWhitespace:!0}),u=new P({limitToBeAddedWhitespace:!0});let f=!0,h=!0,g="";function p(e,t){let r;return E(e,0,t.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&E(e,r,t.tails,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})?e.slice(r):e}for(;e!==p(e,s);)e=K(p(e,s)).res;function y(e,t){let r;return j(e,e.length-1,t.tails,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&r&&j(e,r,t.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})?e.slice(0,r+1):e}for(;e!==y(e,s);)e=K(y(e,s)).res;if(!(s.heads.length&&E(e,0,s.heads,{trimBeforeMatching:!0})&&s.tails.length&&j(e,e.length-1,s.tails,{trimBeforeMatching:!0})))return K(e).res;for(let t=0,r=e.length;t<r;t++)if(""===e[t].trim());else{let r;if(E(e,t,s.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&r){let n;h=!0,f&&(f=!0),E(e,r,s.tails,{trimBeforeMatching:!0,cb:(e,t,r)=>(n=r,!0)})&&l.push(t,n),u.current()&&o&&"tails"!==g&&l.push(u.current()),o||u.current()&&(l.push(u.current()),u.wipe()),u.push(t,r),g="heads",t=r-1;continue}if(E(e,t,s.tails,{trimBeforeMatching:!0,cb:(t,n,i)=>(r=Number.isInteger(i)?i:e.length,!0)})&&r){h=!0,f?("heads"===g&&u.wipe(),f=!1):u.push(t,r),g="tails",t=r-1;continue}f&&(f=!0),h&&!o?(o=!0,h=!1):h&&!a?(a=!0,f=!0,h=!1,"heads"===g&&u.wipe()):h&&a&&u.wipe()}return u.current()&&l.push(u.current()),l.current()?z(e,l.current()).trim():e.trim()}(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return Y(r)?function(e,t,r){let n,i;return"string"==typeof e&&e.length>0&&E(e,0,t,{trimBeforeMatching:!0,cb:(e,t,r)=>(n=r,!0)})&&j(e,e.length-1,r,{trimBeforeMatching:!0,cb:(e,t,r)=>(i=r+1,!0)})?e.slice(n,i):e}(r,t.wrapHeadsWith,t.wrapTailsWith):r}return e}function ue(e,t,r,n){let i;if(-1!==r.indexOf(".")){let s=r,o=!0;if(n.lookForDataContainers&&"string"==typeof n.dataContainerIdentifierTails&&n.dataContainerIdentifierTails.length>0&&!s.endsWith(n.dataContainerIdentifierTails)){const r=_.get(e,s+n.dataContainerIdentifierTails);te(r)&&_.get(r,t)&&(i=_.get(r,t),o=!1)}for(;o&&-1!==s.indexOf(".");){if(s=se(s),oe(s)===t)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop. The parent key "${oe(s)}" is called the same as the variable "${t}" we're looking for.`);if(n.lookForDataContainers&&"string"==typeof n.dataContainerIdentifierTails&&n.dataContainerIdentifierTails.length>0&&!s.endsWith(n.dataContainerIdentifierTails)){const r=_.get(e,s+n.dataContainerIdentifierTails);te(r)&&_.get(r,t)&&(i=_.get(r,t),o=!1)}if(void 0===i){const r=_.get(e,s);te(r)&&_.get(r,t)&&(i=_.get(r,t),o=!1)}}}if(void 0===i){const r=_.get(e,t);void 0!==r&&(i=r)}if(void 0===i)if(-1===t.indexOf(".")){const n=H(e,t);if(n.length>0)for(let e=0,s=n.length;e<s;e++){if(Y(n[e].val)||Z(n[e].val)||ee(n[e].val)){i=n[e].val;break}if("number"==typeof n[e].val){i=String(n[e].val);break}if(Array.isArray(n[e].val)){i=n[e].val.join("");break}throw new Error(`json-variables/findValues(): [THROW_ID_21] While trying to resolve: "${t}" at path "${r}", we actually found the key named ${t}, but it was not equal to a string but to:\n${JSON.stringify(n[e],null,4)}\nWe can't resolve a string with that! It should be a string.`)}}else{const r=H(e,function(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=0,r=e.length;t<r;t++)if("."===e[t])return e.slice(0,t);return e}(t));if(r.length>0)for(let e=0,n=r.length;e<n;e++){const n=_.get(r[e].val,ie(t));n&&Y(n)&&(i=n)}}return i}function fe(e,t,r,n,i=[]){if(i.includes(r)){let e="";if(i.length>1){const t=" →\n";e=i.reduce(((e,n,i)=>e+(0===i?"":t)+(n===r?"💥 ":" ")+n)," Here's the path we travelled up until we hit the recursion:\n\n"),e+=`${t}💥 ${r}`}throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop, the key is referencing itself."${e}`)}const s={},o=Array.from(i);o.push(r);const a=new P;function l(i,l,u){for(let f=0,h=i.length;f<h;f++){const h=i[f],c=t.slice(h.headsEndAt,h.tailsStartAt);if(0===c.length)a.push(h.headsStartAt,h.tailsEndAt);else if(Q.call(s,c)&&Y(s[c]))a.push(h.headsStartAt,h.tailsEndAt,s[c]);else{let i=ue(e,c.trim(),r,n);if(void 0===i)if(!0===n.allowUnresolved)i="";else{if("string"!=typeof n.allowUnresolved)throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${t.slice(h.headsEndAt,h.tailsStartAt)}. We're at path: "${r}".`);i=n.allowUnresolved}if(!u&&n.throwWhenNonStringInsertedInString&&!Y(i))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${t.slice(h.headsEndAt,h.tailsStartAt)} at path ${r}, it resolved into a non-string value, ${JSON.stringify(i,null,4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);if(Z(i)){if(n.resolveToBoolIfAnyValuesContainBool)return a.wipe(),!n.resolveToFalseIfAnyValuesContainBool&&i;i=""}else{if(ee(i)&&u)return a.wipe(),i;i=Array.isArray(i)?String(i.join("")):ee(i)?"":String(i)}const f=r.includes(".")?`${se(r)}.${c}`:c;if(ae(i,n)){const t=le(fe(e,i,f,n,o),n,l,0,0,c.trim());Y(t)&&a.push(h.headsStartAt,h.tailsEndAt,t)}else{s[c]=i;const e=le(i,n,l,0,0,c.trim());Y(e)&&a.push(h.headsStartAt,h.tailsEndAt,e)}}}}let u;try{u=N(t,n.heads,n.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(e){throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${t}" at path ${r}, something wrong with heads and tails was detected! Here's the internal error message:\n${e}`)}let f=!1;1===u.length&&""===z(t,[[u[0].headsStartAt,u[0].tailsEndAt]]).trim()&&(f=!0);const h=l(u,!1,f);if(Z(h))return h;if(ee(h))return h;try{u=N(t,n.headsNoWrap,n.tailsNoWrap,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(e){throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${t}" at path ${r}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:\n${e}`)}1===u.length&&""===z(t,[[u[0].headsStartAt,u[0].tailsEndAt]]).trim()&&(f=!0);const c=l(u,!0,f);return Z(c)||ee(c)?c:a&&a.current()?z(t,a.current()):t}e.defaults=X,e.jVar=function(e,t){if(!arguments.length)throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");if(!te(e))throw new TypeError("json-variables/jVar(): [THROW_ID_02] Alas! The input must be a plain object! Currently it's: "+(Array.isArray(e)?"array":typeof e));if(t&&!te(t))throw new TypeError("json-variables/jVar(): [THROW_ID_03] Alas! An Optional Options Object must be a plain object! Currently it's: "+(Array.isArray(t)?"array":typeof t));const r={...X,...t};let n,i,s;if(r.dontWrapVars?Array.isArray(r.dontWrapVars)||(r.dontWrapVars=T(r.dontWrapVars)):r.dontWrapVars=[],r.dontWrapVars.length>0&&!r.dontWrapVars.every(((e,t)=>!!Y(e)||(n=e,i=t,!1))))throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in opts.dontWrapVars should be of a string type. Computer detected a value "${n}" at index ${i}, which is not string but ${Array.isArray(n)?"array":typeof n}!`);if(""===r.heads)throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");if(""===r.tails)throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");if(r.lookForDataContainers&&""===r.dataContainerIdentifierTails)throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");if(r.heads===r.tails)throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");if(r.heads===r.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");if(r.tails===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");if(""===r.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");if(""===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");if(r.headsNoWrap===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");return p(e,((t,n,i)=>{if(re(n)&&ae(t,r))throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!\nPlease check the following key: ${t}`);if(s=void 0!==n?n:t,""===s)return s;if(0!==r.heads.length&&ne(s)===ne(r.heads)||0!==r.tails.length&&ne(s)===ne(r.tails)||0!==r.headsNoWrap.length&&ne(s)===ne(r.headsNoWrap)||0!==r.tailsNoWrap.length&&ne(s)===ne(r.tailsNoWrap)){if(!r.noSingleMarkers)return s;throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${ne(s)} which is equal to ${ne(s)===ne(r.heads)?"heads":""}${ne(s)===ne(r.tails)?"tails":""}${Y(r.headsNoWrap)&&ne(s)===ne(r.headsNoWrap)?"headsNoWrap":""}${Y(r.tailsNoWrap)&&ne(s)===ne(r.tailsNoWrap)?"tailsNoWrap":""}. If you wouldn't have set opts.noSingleMarkers to "true" this error would not happen and computer would have left the current element (${ne(s)}) alone`)}return Y(s)&&ae(s,r)?fe(e,s,i.path,r):s}))},e.version="11.0.3",Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-variables",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.3",
|
|
4
4
|
"description": "Resolves custom-marked, cross-referenced paths in parsed JSON",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"comb",
|
|
@@ -41,11 +41,13 @@
|
|
|
41
41
|
"types": "types/index.d.ts",
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "rollup -c",
|
|
44
|
-
"esbuild": "node '../../scripts/esbuild.js'",
|
|
45
|
-
"esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
46
44
|
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
|
|
45
|
+
"clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
|
|
46
|
+
"clean_types": "../../scripts/cleanTypes.js",
|
|
47
47
|
"dev": "rollup -c --dev",
|
|
48
48
|
"devunittest": "npm run dev && tap --only -R 'base'",
|
|
49
|
+
"esbuild": "node '../../scripts/esbuild.js'",
|
|
50
|
+
"esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
49
51
|
"format": "npm run lect && npm run prettier && npm run lint",
|
|
50
52
|
"lect": "lect",
|
|
51
53
|
"lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
|
|
@@ -53,13 +55,11 @@
|
|
|
53
55
|
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
|
|
54
56
|
"republish": "npm publish || :",
|
|
55
57
|
"tap": "tap",
|
|
56
|
-
"tsc": "tsc",
|
|
57
58
|
"pretest": "npm run build",
|
|
58
59
|
"test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
|
|
59
60
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"clean_types": "../../scripts/cleanTypes.js"
|
|
61
|
+
"tsc": "tsc",
|
|
62
|
+
"unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
|
|
63
63
|
},
|
|
64
64
|
"tap": {
|
|
65
65
|
"check-coverage": false,
|
|
@@ -86,55 +86,55 @@
|
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@babel/runtime": "^7.
|
|
90
|
-
"arrayiffy-if-string": "^4.0.
|
|
91
|
-
"ast-get-values-by-key": "^4.0.
|
|
92
|
-
"ast-monkey-traverse": "^3.0.
|
|
93
|
-
"matcher": "^
|
|
94
|
-
"object-path": "^0.11.
|
|
95
|
-
"ranges-apply": "^6.0.
|
|
96
|
-
"ranges-push": "^6.0.
|
|
97
|
-
"string-find-heads-tails": "^5.0.
|
|
98
|
-
"string-match-left-right": "^8.0.
|
|
99
|
-
"string-remove-duplicate-heads-tails": "^6.0.
|
|
89
|
+
"@babel/runtime": "^7.16.0",
|
|
90
|
+
"arrayiffy-if-string": "^4.0.3",
|
|
91
|
+
"ast-get-values-by-key": "^4.0.3",
|
|
92
|
+
"ast-monkey-traverse": "^3.0.3",
|
|
93
|
+
"matcher": "^5.0.0",
|
|
94
|
+
"object-path": "^0.11.8",
|
|
95
|
+
"ranges-apply": "^6.0.3",
|
|
96
|
+
"ranges-push": "^6.0.3",
|
|
97
|
+
"string-find-heads-tails": "^5.0.3",
|
|
98
|
+
"string-match-left-right": "^8.0.3",
|
|
99
|
+
"string-remove-duplicate-heads-tails": "^6.0.3"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
|
-
"@babel/cli": "^7.
|
|
103
|
-
"@babel/core": "^7.
|
|
104
|
-
"@babel/node": "^7.
|
|
105
|
-
"@babel/plugin-external-helpers": "^7.
|
|
106
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
107
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.
|
|
108
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.
|
|
109
|
-
"@babel/plugin-proposal-optional-chaining": "^7.
|
|
110
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
111
|
-
"@babel/preset-env": "^7.
|
|
112
|
-
"@babel/preset-typescript": "^7.
|
|
113
|
-
"@babel/register": "^7.
|
|
102
|
+
"@babel/cli": "^7.16.0",
|
|
103
|
+
"@babel/core": "^7.16.0",
|
|
104
|
+
"@babel/node": "^7.16.0",
|
|
105
|
+
"@babel/plugin-external-helpers": "^7.16.0",
|
|
106
|
+
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
107
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
108
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
109
|
+
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
110
|
+
"@babel/plugin-transform-runtime": "^7.16.0",
|
|
111
|
+
"@babel/preset-env": "^7.16.0",
|
|
112
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
113
|
+
"@babel/register": "^7.16.0",
|
|
114
114
|
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
115
115
|
"@rollup/plugin-babel": "^5.3.0",
|
|
116
|
-
"@rollup/plugin-commonjs": "^
|
|
116
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
117
117
|
"@rollup/plugin-json": "^4.1.0",
|
|
118
|
-
"@rollup/plugin-node-resolve": "^13.0.
|
|
118
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
119
119
|
"@rollup/plugin-strip": "^2.1.0",
|
|
120
|
-
"@rollup/plugin-typescript": "^8.
|
|
121
|
-
"@types/node": "^16.
|
|
120
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
|
121
|
+
"@types/node": "^16.11.6",
|
|
122
122
|
"@types/tap": "^15.0.5",
|
|
123
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
124
|
-
"@typescript-eslint/parser": "^
|
|
125
|
-
"core-js": "^3.
|
|
123
|
+
"@typescript-eslint/eslint-plugin": "^5.2.0",
|
|
124
|
+
"@typescript-eslint/parser": "^5.2.0",
|
|
125
|
+
"core-js": "^3.19.0",
|
|
126
126
|
"cross-env": "^7.0.3",
|
|
127
|
-
"eslint": "^
|
|
128
|
-
"lect": "^0.18.
|
|
129
|
-
"rollup": "^2.
|
|
127
|
+
"eslint": "^8.1.0",
|
|
128
|
+
"lect": "^0.18.3",
|
|
129
|
+
"rollup": "^2.59.0",
|
|
130
130
|
"rollup-plugin-ascii": "^0.0.3",
|
|
131
131
|
"rollup-plugin-banner": "^0.2.1",
|
|
132
132
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
133
133
|
"rollup-plugin-dts": "^4.0.0",
|
|
134
134
|
"rollup-plugin-terser": "^7.0.2",
|
|
135
|
-
"tap": "^15.0.
|
|
135
|
+
"tap": "^15.0.10",
|
|
136
136
|
"tslib": "^2.3.1",
|
|
137
|
-
"typescript": "^4.4.
|
|
137
|
+
"typescript": "^4.4.4"
|
|
138
138
|
},
|
|
139
139
|
"engines": {
|
|
140
140
|
"node": ">=12"
|