@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.
- package/dist/cjs/string.js +3 -3
- package/dist/esm/string.js +3 -3
- package/package.json +1 -1
- package/string.js +14 -2
package/dist/cjs/string.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);let s=-1,c=-1,
|
|
3
|
-
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),
|
|
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)));
|
package/dist/esm/string.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const
|
|
2
|
-
`);let
|
|
3
|
-
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),
|
|
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
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
|
-
|
|
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 || {}
|