@symbo.ls/utils 3.14.778 → 3.14.779

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.
@@ -1,3 +1,3 @@
1
- "use strict";var _=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var N=(e,n)=>{for(var t in n)_(e,t,{get:n[t],enumerable:!0})},O=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let c of L(n))!j.call(e,c)&&c!==t&&_(e,c,{get:()=>n[c],enumerable:!(s=A(n,c))||s.enumerable});return e};var R=e=>O(_({},"__esModule",{value:!0}),e);var M={};N(M,{customDecodeURIComponent:()=>z,customEncodeURIComponent:()=>q,decodeNewlines:()=>K,encodeNewlines:()=>D,findKeyPosition:()=>v,lowercaseFirstLetter:()=>T,replaceLiteralsWithObjectFields:()=>F,replaceOctalEscapeSequences:()=>V,stringIncludesAny:()=>I,trimStringFromSymbols:()=>k});module.exports=R(M);const I=(e,n)=>{for(const t of n)if(e.includes(t))return!0;return!1},k=(e,n)=>{const t=new RegExp(`[${n.join("\\")}]`,"g");return e.replace(t,"")},E={2:/{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,3:/{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g},x=(e,n)=>n.split(".").reduce((t,s)=>t?.[s],e),$=(e,n)=>{if(!e||!e.__ref)return!0;let t=e;for(;t;){if(t.allowRuntimeTemplates===!0)return!0;const s=t.__ref&&t.__ref.__authoredTemplates;if(s&&s.has(n))return!0;t=t.parent}return!1};function F(e,n,t={}){const{bracketsLength:s=2}=t,c=s===3?"{{{":"{{";if(!e.includes(c)||!$(this,e))return e;const m=E[s],a=n||this.state||{},u=this;return e.replace(m,(p,d,r,i)=>{const g=r.trim();if(i){const l=u?.context,o=l?.functions?.[i]||l?.utils?.[i]||l?.methods?.[i]||l?.snippets?.[i]||u?.[i];if(o&&typeof o=="function")try{return String(o.call(u,g)??"")}catch{return""}return""}if(d){const l=(d.match(/\.\.\//g)||[]).length;let o=a;for(let f=0;f<l;f++){if(!o||!o.parent)return"";o=o.parent}if(g==="parent")return String(o.value??"");const h=x(o,g);return h!=null&&typeof h=="object"?"":String(h??"")}else{const l=x(a,g);if(l!=null&&typeof l!="object")return String(l);const o=u?.context?.polyglot;if(o?.translations){const h=a?.root?.lang||a?.lang||u?.context?.state?.lang||o.defaultLang||"en",f=o.translations[h];if(f){const C=x(f,g);if(C!=null&&typeof C!="object")return String(C);for(const w in f){const b=f[w];if(b&&typeof b=="object"&&!Array.isArray(b)){const S=x(b,g);if(S!=null&&typeof S!="object")return String(S)}}}const y=x(o.translations,g);if(y!=null&&typeof y!="object")return String(y)}return""}})}const T=e=>`${e.charAt(0).toLowerCase()}${e.slice(1)}`,v=(e,n)=>{const t=e.split(`
2
- `);let s=-1,c=-1,m=-1,a=-1;const u=new RegExp(`\\b${n}\\b\\s*:\\s*`);let p=0,d=!1;for(let r=0;r<t.length;r++)if(u.test(t[r])&&!d){if(d=!0,s=r+1,m=t[r].indexOf(n)+1,t[r].includes("{}")){c=s,a=t[r].indexOf("{}")+3;break}const i=t[r].slice(m+n.length);if(i.includes("{")||i.includes("["))p=1;else{c=r+1,a=t[r].length+1;break}}else if(d&&(p+=(t[r].match(/{/g)||[]).length,p+=(t[r].match(/\[/g)||[]).length,p-=(t[r].match(/}/g)||[]).length,p-=(t[r].match(/]/g)||[]).length,p===0)){c=r+1,a=t[r].lastIndexOf("}")!==-1?t[r].lastIndexOf("}")+2:t[r].length+1;break}return{startColumn:m,endColumn:a,startLineNumber:s,endLineNumber:c}},U=/\\([0-7]{1,3})/g,V=e=>e.replace(U,(n,t)=>String.fromCharCode(parseInt(t,8))),D=e=>e.replace(/\n/g,"/////n").replace(/`/g,"/////tilde").replace(/\$/g,"/////dlrsgn"),K=e=>e.replace(/\/\/\/\/\/n/g,`
3
- `).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),P=/[^a-zA-Z0-9\s]/g,q=e=>e.replace(P,n=>"%"+n.charCodeAt(0).toString(16).toUpperCase()),z=e=>e.replace(/%[0-9A-Fa-f]{2}/g,n=>String.fromCharCode(parseInt(n.slice(1),16)));
1
+ "use strict";var w=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var O=(e,n)=>{for(var t in n)w(e,t,{get:n[t],enumerable:!0})},R=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let c of j(n))!N.call(e,c)&&c!==t&&w(e,c,{get:()=>n[c],enumerable:!(s=L(n,c))||s.enumerable});return e};var I=e=>R(w({},"__esModule",{value:!0}),e);var W={};O(W,{customDecodeURIComponent:()=>M,customEncodeURIComponent:()=>z,decodeNewlines:()=>P,encodeNewlines:()=>K,findKeyPosition:()=>U,lowercaseFirstLetter:()=>v,replaceLiteralsWithObjectFields:()=>T,replaceOctalEscapeSequences:()=>D,stringIncludesAny:()=>k,trimStringFromSymbols:()=>E});module.exports=I(W);const k=(e,n)=>{for(const t of n)if(e.includes(t))return!0;return!1},E=(e,n)=>{const t=new RegExp(`[${n.join("\\")}]`,"g");return e.replace(t,"")},$={2:/{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,3:/{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g},m=(e,n)=>n.split(".").reduce((t,s)=>t?.[s],e),F=(e,n)=>{if(!e||!e.__ref)return!0;let t=e;for(;t;){if(t.allowRuntimeTemplates===!0)return!0;const s=t.__ref&&t.__ref.__authoredTemplates;if(s&&s.has(n))return!0;t=t.parent}return!1};function T(e,n,t={}){const{bracketsLength:s=2,authored:c=!1}=t,h=s===3?"{{{":"{{";if(!e.includes(h)||c!==!0&&!F(this,e))return e;const p=$[s],f=n||this.state||{},l=this;return e.replace(p,(x,r,b,g)=>{const i=b.trim();if(g){const a=l?.context,o=a?.functions?.[g]||a?.utils?.[g]||a?.methods?.[g]||a?.snippets?.[g]||l?.[g];if(o&&typeof o=="function")try{return String(o.call(l,i)??"")}catch{return""}return""}if(r){const a=(r.match(/\.\.\//g)||[]).length;let o=f;for(let u=0;u<a;u++){if(!o||!o.parent)return"";o=o.parent}if(i==="parent")return String(o.value??"");const d=m(o,i);return d!=null&&typeof d=="object"?"":String(d??"")}else{const a=m(f,i);if(a!=null&&typeof a!="object")return String(a);const o=l?.context?.polyglot;if(o?.translations){const d=f?.root?.lang||f?.lang||l?.context?.state?.lang||o.defaultLang||"en",u=o.translations[d];if(u){const S=m(u,i);if(S!=null&&typeof S!="object")return String(S);for(const A in u){const y=u[A];if(y&&typeof y=="object"&&!Array.isArray(y)){const _=m(y,i);if(_!=null&&typeof _!="object")return String(_)}}}const C=m(o.translations,i);if(C!=null&&typeof C!="object")return String(C)}return""}})}const v=e=>`${e.charAt(0).toLowerCase()}${e.slice(1)}`,U=(e,n)=>{const t=e.split(`
2
+ `);let s=-1,c=-1,h=-1,p=-1;const f=new RegExp(`\\b${n}\\b\\s*:\\s*`);let l=0,x=!1;for(let r=0;r<t.length;r++)if(f.test(t[r])&&!x){if(x=!0,s=r+1,h=t[r].indexOf(n)+1,t[r].includes("{}")){c=s,p=t[r].indexOf("{}")+3;break}const b=t[r].slice(h+n.length);if(b.includes("{")||b.includes("["))l=1;else{c=r+1,p=t[r].length+1;break}}else if(x&&(l+=(t[r].match(/{/g)||[]).length,l+=(t[r].match(/\[/g)||[]).length,l-=(t[r].match(/}/g)||[]).length,l-=(t[r].match(/]/g)||[]).length,l===0)){c=r+1,p=t[r].lastIndexOf("}")!==-1?t[r].lastIndexOf("}")+2:t[r].length+1;break}return{startColumn:h,endColumn:p,startLineNumber:s,endLineNumber:c}},V=/\\([0-7]{1,3})/g,D=e=>e.replace(V,(n,t)=>String.fromCharCode(parseInt(t,8))),K=e=>e.replace(/\n/g,"/////n").replace(/`/g,"/////tilde").replace(/\$/g,"/////dlrsgn"),P=e=>e.replace(/\/\/\/\/\/n/g,`
3
+ `).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),q=/[^a-zA-Z0-9\s]/g,z=e=>e.replace(q,n=>"%"+n.charCodeAt(0).toString(16).toUpperCase()),M=e=>e.replace(/%[0-9A-Fa-f]{2}/g,n=>String.fromCharCode(parseInt(n.slice(1),16)));
@@ -1,3 +1,3 @@
1
- const N=(t,r)=>{for(const e of r)if(t.includes(e))return!0;return!1},O=(t,r)=>{const e=new RegExp(`[${r.join("\\")}]`,"g");return t.replace(e,"")},w={2:/{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,3:/{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g},x=(t,r)=>r.split(".").reduce((e,s)=>e?.[s],t),A=(t,r)=>{if(!t||!t.__ref)return!0;let e=t;for(;e;){if(e.allowRuntimeTemplates===!0)return!0;const s=e.__ref&&e.__ref.__authoredTemplates;if(s&&s.has(r))return!0;e=e.parent}return!1};function R(t,r,e={}){const{bracketsLength:s=2}=e,f=s===3?"{{{":"{{";if(!t.includes(f)||!A(this,t))return t;const m=w[s],l=r||this.state||{},i=this;return t.replace(m,(u,d,n,a)=>{const p=n.trim();if(a){const c=i?.context,o=c?.functions?.[a]||c?.utils?.[a]||c?.methods?.[a]||c?.snippets?.[a]||i?.[a];if(o&&typeof o=="function")try{return String(o.call(i,p)??"")}catch{return""}return""}if(d){const c=(d.match(/\.\.\//g)||[]).length;let o=l;for(let g=0;g<c;g++){if(!o||!o.parent)return"";o=o.parent}if(p==="parent")return String(o.value??"");const h=x(o,p);return h!=null&&typeof h=="object"?"":String(h??"")}else{const c=x(l,p);if(c!=null&&typeof c!="object")return String(c);const o=i?.context?.polyglot;if(o?.translations){const h=l?.root?.lang||l?.lang||i?.context?.state?.lang||o.defaultLang||"en",g=o.translations[h];if(g){const C=x(g,p);if(C!=null&&typeof C!="object")return String(C);for(const _ in g){const b=g[_];if(b&&typeof b=="object"&&!Array.isArray(b)){const S=x(b,p);if(S!=null&&typeof S!="object")return String(S)}}}const y=x(o.translations,p);if(y!=null&&typeof y!="object")return String(y)}return""}})}const I=t=>`${t.charAt(0).toLowerCase()}${t.slice(1)}`,k=(t,r)=>{const e=t.split(`
2
- `);let s=-1,f=-1,m=-1,l=-1;const i=new RegExp(`\\b${r}\\b\\s*:\\s*`);let u=0,d=!1;for(let n=0;n<e.length;n++)if(i.test(e[n])&&!d){if(d=!0,s=n+1,m=e[n].indexOf(r)+1,e[n].includes("{}")){f=s,l=e[n].indexOf("{}")+3;break}const a=e[n].slice(m+r.length);if(a.includes("{")||a.includes("["))u=1;else{f=n+1,l=e[n].length+1;break}}else if(d&&(u+=(e[n].match(/{/g)||[]).length,u+=(e[n].match(/\[/g)||[]).length,u-=(e[n].match(/}/g)||[]).length,u-=(e[n].match(/]/g)||[]).length,u===0)){f=n+1,l=e[n].lastIndexOf("}")!==-1?e[n].lastIndexOf("}")+2:e[n].length+1;break}return{startColumn:m,endColumn:l,startLineNumber:s,endLineNumber:f}},L=/\\([0-7]{1,3})/g,E=t=>t.replace(L,(r,e)=>String.fromCharCode(parseInt(e,8))),$=t=>t.replace(/\n/g,"/////n").replace(/`/g,"/////tilde").replace(/\$/g,"/////dlrsgn"),F=t=>t.replace(/\/\/\/\/\/n/g,`
3
- `).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),j=/[^a-zA-Z0-9\s]/g,T=t=>t.replace(j,r=>"%"+r.charCodeAt(0).toString(16).toUpperCase()),v=t=>t.replace(/%[0-9A-Fa-f]{2}/g,r=>String.fromCharCode(parseInt(r.slice(1),16)));export{v as customDecodeURIComponent,T as customEncodeURIComponent,F as decodeNewlines,$ as encodeNewlines,k as findKeyPosition,I as lowercaseFirstLetter,R as replaceLiteralsWithObjectFields,E as replaceOctalEscapeSequences,N as stringIncludesAny,O as trimStringFromSymbols};
1
+ const O=(t,r)=>{for(const e of r)if(t.includes(e))return!0;return!1},R=(t,r)=>{const e=new RegExp(`[${r.join("\\")}]`,"g");return t.replace(e,"")},A={2:/{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,3:/{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g},m=(t,r)=>r.split(".").reduce((e,c)=>e?.[c],t),L=(t,r)=>{if(!t||!t.__ref)return!0;let e=t;for(;e;){if(e.allowRuntimeTemplates===!0)return!0;const c=e.__ref&&e.__ref.__authoredTemplates;if(c&&c.has(r))return!0;e=e.parent}return!1};function I(t,r,e={}){const{bracketsLength:c=2,authored:u=!1}=e,h=c===3?"{{{":"{{";if(!t.includes(h)||u!==!0&&!L(this,t))return t;const p=A[c],f=r||this.state||{},s=this;return t.replace(p,(x,n,b,g)=>{const a=b.trim();if(g){const l=s?.context,o=l?.functions?.[g]||l?.utils?.[g]||l?.methods?.[g]||l?.snippets?.[g]||s?.[g];if(o&&typeof o=="function")try{return String(o.call(s,a)??"")}catch{return""}return""}if(n){const l=(n.match(/\.\.\//g)||[]).length;let o=f;for(let i=0;i<l;i++){if(!o||!o.parent)return"";o=o.parent}if(a==="parent")return String(o.value??"");const d=m(o,a);return d!=null&&typeof d=="object"?"":String(d??"")}else{const l=m(f,a);if(l!=null&&typeof l!="object")return String(l);const o=s?.context?.polyglot;if(o?.translations){const d=f?.root?.lang||f?.lang||s?.context?.state?.lang||o.defaultLang||"en",i=o.translations[d];if(i){const S=m(i,a);if(S!=null&&typeof S!="object")return String(S);for(const w in i){const y=i[w];if(y&&typeof y=="object"&&!Array.isArray(y)){const _=m(y,a);if(_!=null&&typeof _!="object")return String(_)}}}const C=m(o.translations,a);if(C!=null&&typeof C!="object")return String(C)}return""}})}const k=t=>`${t.charAt(0).toLowerCase()}${t.slice(1)}`,E=(t,r)=>{const e=t.split(`
2
+ `);let c=-1,u=-1,h=-1,p=-1;const f=new RegExp(`\\b${r}\\b\\s*:\\s*`);let s=0,x=!1;for(let n=0;n<e.length;n++)if(f.test(e[n])&&!x){if(x=!0,c=n+1,h=e[n].indexOf(r)+1,e[n].includes("{}")){u=c,p=e[n].indexOf("{}")+3;break}const b=e[n].slice(h+r.length);if(b.includes("{")||b.includes("["))s=1;else{u=n+1,p=e[n].length+1;break}}else if(x&&(s+=(e[n].match(/{/g)||[]).length,s+=(e[n].match(/\[/g)||[]).length,s-=(e[n].match(/}/g)||[]).length,s-=(e[n].match(/]/g)||[]).length,s===0)){u=n+1,p=e[n].lastIndexOf("}")!==-1?e[n].lastIndexOf("}")+2:e[n].length+1;break}return{startColumn:h,endColumn:p,startLineNumber:c,endLineNumber:u}},j=/\\([0-7]{1,3})/g,$=t=>t.replace(j,(r,e)=>String.fromCharCode(parseInt(e,8))),F=t=>t.replace(/\n/g,"/////n").replace(/`/g,"/////tilde").replace(/\$/g,"/////dlrsgn"),T=t=>t.replace(/\/\/\/\/\/n/g,`
3
+ `).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),N=/[^a-zA-Z0-9\s]/g,v=t=>t.replace(N,r=>"%"+r.charCodeAt(0).toString(16).toUpperCase()),U=t=>t.replace(/%[0-9A-Fa-f]{2}/g,r=>String.fromCharCode(parseInt(r.slice(1),16)));export{U as customDecodeURIComponent,v as customEncodeURIComponent,T as decodeNewlines,F as encodeNewlines,E as findKeyPosition,k as lowercaseFirstLetter,I as replaceLiteralsWithObjectFields,$ as replaceOctalEscapeSequences,O as stringIncludesAny,R as trimStringFromSymbols};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/utils",
3
- "version": "3.14.778",
3
+ "version": "3.14.779",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "type": "module",
6
6
  "module": "./dist/esm/index.js",
package/string.js CHANGED
@@ -60,6 +60,16 @@ const getNestedValue = (obj, path) => {
60
60
  * function invocation from that element's content — never set it on an
61
61
  * element that renders text a user or a model produced.
62
62
  *
63
+ * `{ authored: true }` in `replaceLiteralsWithObjectFields`' options is the
64
+ * one other authority, and it is per CALL: the caller states that it read
65
+ * THIS string as a literal out of a project definition, so it is author-time
66
+ * by construction. `@symbo.ls/helmet`'s `extractMetadata` is that caller — it
67
+ * reads page and app `metadata` straight out of project data and resolves
68
+ * them against the ROOT element (brender's SSR head), while a page literal is
69
+ * only ever recorded on the page element `create()` built. Never pass it for
70
+ * a string a factory returned, a state value or any other data: the flag is
71
+ * a claim about where the string came from, and nothing checks it.
72
+ *
63
73
  * This reads `this` by duck-typing (`__ref`, `parent`), exactly as the state
64
74
  * and polyglot lookups below already do — `utils` never imports `element`.
65
75
  * A caller with no `__ref` is not an element (a bare util call, a test) and
@@ -78,10 +88,12 @@ const isAuthoredTemplate = (element, str) => {
78
88
  }
79
89
 
80
90
  export function replaceLiteralsWithObjectFields (str, state, options = {}) {
81
- const { bracketsLength = 2 } = options
91
+ const { bracketsLength = 2, authored = false } = options
82
92
  const bracketPattern = bracketsLength === 3 ? '{{{' : '{{'
83
93
  if (!str.includes(bracketPattern)) return str
84
- if (!isAuthoredTemplate(this, str)) return str
94
+ // `authored` — see isAuthoredTemplate: a caller holding the definition
95
+ // vouches for this one literal. Anything else needs the element record.
96
+ if (authored !== true && !isAuthoredTemplate(this, str)) return str
85
97
 
86
98
  const reg = brackRegex[bracketsLength]
87
99
  const obj = state || this.state || {}