@scbt-ecom/ui 0.165.0 → 0.166.0
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/lib/shared/utils/variablesByNikita/VariablesFork.js +2 -0
- package/dist/lib/shared/utils/variablesByNikita/VariablesFork.js.map +1 -0
- package/dist/lib/shared/utils/variablesByNikita/index.js +2 -0
- package/dist/lib/shared/utils/variablesByNikita/index.js.map +1 -0
- package/dist/stats.html +1 -1
- package/dist/types/lib/shared/utils/variablesByNikita/VariablesFork.d.ts +28 -0
- package/dist/types/lib/shared/utils/variablesByNikita/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{TypeGuards as i}from"../typeGuards.js";class u{static regexes=[/\$\{([^}]+)}/g,/@\{([^}]+)}/g];static allowedPrefixes=["$","@","#"];constructor(){}static matchVariables(e){const r=[];for(const t of this.regexes){const s=e.match(t);s&&r.push(...s)}return r}static wrap(e,r){return`${r}{${e}}`}static unwrap(e){if(!(e.length>1))return e;const r=e[0],t=e[1];return this.allowedPrefixes.includes(r)&&t==="{"&&e.endsWith("}")?e.slice(2,-1):e}static mapKeysToVariables(e,r){const t=[];for(const s of r)e?.includes(s.key)&&t.push(s);return t}static interpolate(e,r){let t=e,s=this.matchVariables(e),c=this.mapKeysToVariables(s??[],r);for(;!i.isArrayEmpty(c);)c.forEach(({key:o,value:a})=>{t=t.replace(o,a)}),s=this.matchVariables(t),c=this.mapKeysToVariables(s??[],c);return t}static structureInterpolate(e,r){if(typeof e=="string")return this.interpolate(e,r);if(i.isArray(e))return e.map(t=>this.structureInterpolate(t,r));if(typeof e=="object"&&e!==null){const t={},s=Object.keys(e);for(const c of s)t[c]=this.structureInterpolate(e[c],r);return t}return e}}export{u as VariablesFork};
|
|
2
|
+
//# sourceMappingURL=VariablesFork.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VariablesFork.js","sources":["../../../../../lib/shared/utils/variablesByNikita/VariablesFork.ts"],"sourcesContent":["import { TypeGuards } from '../typeGuards'\n\nexport interface Variable {\n key: string\n value: string\n description: string\n}\n\n/** Что нам для этого нужно\n * 1. Реализация CRUD для переменных в админке\n * 2.\n * - Нужно реализовать функцию traverseToData чтобы бежать по всей структуре данных\n * - Нужно реализовать функцию, которая ищет в строке переменную matchVarsFromString, и возвращает массив ключей переменных\n * - Для match нужно описать регулярку, которая матчит переменную, а так же добавить возможно прокидывать регулярку в конструктор\n * - Нужно реализовать функцию, которая массив ключей транформирует в entries [[${var}, 'boba'], [${var2}, 'biba']], чтобы трансформировать нужно написать метод entriesOf\n * - entriesOf метод, который сравнивает айтемы с бэка с текущим ключом и возвратает entries [[${var}, 'boba'], [${var2}, 'biba']]\n * - Потом нужно в текущей строке подменить ключ на value, делаем мы это через перебор всех переменных, которые мы нашли в строке\n * - Нужно ещё раз пробежатся по итовой строке, и проверить её на переменные с помощью функции matchVarsFromString\n * - Нужно добавить функции wrap и unwrap\n */\n\nexport class VariablesFork {\n private static regexes = [/\\$\\{([^}]+)}/g, /@\\{([^}]+)}/g]\n private static allowedPrefixes = ['$', '@', '#'] as const\n\n private constructor() {}\n\n static matchVariables(string: string) {\n const result = []\n for (const regex of this.regexes) {\n const matched = string.match(regex)\n\n if (matched) {\n result.push(...matched)\n }\n }\n\n return result\n }\n\n static wrap(string: string, prefix: (typeof this.allowedPrefixes)[number] | string) {\n return `${prefix}{${string}}`\n }\n\n static unwrap(string: (typeof this.allowedPrefixes)[number] | string): string {\n if (!(string.length > 1)) return string\n\n const firstChar = string[0]\n const secondChar = string[1]\n const isWrapped =\n this.allowedPrefixes.includes(firstChar as (typeof this.allowedPrefixes)[number]) &&\n secondChar === '{' &&\n string.endsWith('}')\n\n if (isWrapped) {\n return string.slice(2, -1)\n }\n\n return string\n }\n\n static mapKeysToVariables(keys: string[] | null, variables: Variable[]) {\n const entries = []\n\n for (const variable of variables) {\n if (keys?.includes(variable.key)) {\n entries.push(variable)\n }\n }\n\n return entries\n }\n\n static interpolate(string: string, variables: Variable[]) {\n let str = string\n\n let matches = this.matchVariables(string)\n let detectedVariables = this.mapKeysToVariables(matches ?? [], variables)\n\n while (!TypeGuards.isArrayEmpty(detectedVariables)) {\n detectedVariables.forEach(({ key, value }) => {\n str = str.replace(key, value)\n })\n\n matches = this.matchVariables(str)\n detectedVariables = this.mapKeysToVariables(matches ?? [], detectedVariables)\n }\n\n return str\n }\n\n static structureInterpolate<T>(data: T, variables: Variable[]): T {\n if (typeof data === 'string') {\n return this.interpolate(data, variables) as T\n }\n\n if (TypeGuards.isArray(data)) {\n return data.map((item) => this.structureInterpolate(item, variables)) as T\n }\n\n if (typeof data === 'object' && data !== null) {\n const processed = {} as Record<keyof T, unknown>\n const keys = Object.keys(data) as (keyof T)[]\n\n for (const key of keys) {\n processed[key] = this.structureInterpolate(data[key], variables)\n }\n\n return processed as T\n }\n\n return data\n }\n}\n"],"names":["VariablesFork","string","result","regex","matched","prefix","firstChar","secondChar","keys","variables","entries","variable","str","matches","detectedVariables","TypeGuards","key","value","data","item","processed"],"mappings":"8CAqBO,MAAMA,CAAc,CACzB,OAAe,QAAU,CAAC,gBAAiB,cAAc,EACzD,OAAe,gBAAkB,CAAC,IAAK,IAAK,GAAG,EAEvC,aAAc,CAAC,CAEvB,OAAO,eAAeC,EAAgB,CACpC,MAAMC,EAAS,CAAA,EACf,UAAWC,KAAS,KAAK,QAAS,CAChC,MAAMC,EAAUH,EAAO,MAAME,CAAK,EAE9BC,GACFF,EAAO,KAAK,GAAGE,CAAO,CAE1B,CAEA,OAAOF,CACT,CAEA,OAAO,KAAKD,EAAgBI,EAAwD,CAClF,MAAO,GAAGA,CAAM,IAAIJ,CAAM,GAC5B,CAEA,OAAO,OAAOA,EAAgE,CAC5E,GAAI,EAAEA,EAAO,OAAS,GAAI,OAAOA,EAEjC,MAAMK,EAAYL,EAAO,CAAC,EACpBM,EAAaN,EAAO,CAAC,EAM3B,OAJE,KAAK,gB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