@intlayer/editor 4.1.11 → 5.0.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.
Files changed (53) hide show
  1. package/dist/cjs/index.cjs +0 -2
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/server/writeContentDeclaration.cjs.map +1 -1
  4. package/dist/esm/index.mjs +0 -1
  5. package/dist/esm/index.mjs.map +1 -1
  6. package/dist/esm/server/writeContentDeclaration.mjs.map +1 -1
  7. package/dist/types/index.d.ts +0 -1
  8. package/dist/types/index.d.ts.map +1 -1
  9. package/dist/types/server/writeContentDeclaration.d.ts +2 -2
  10. package/dist/types/server/writeContentDeclaration.d.ts.map +1 -1
  11. package/package.json +7 -7
  12. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +0 -85
  13. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +0 -1
  14. package/dist/cjs/dictionaryManipulator/getDictionaryValueByKeyPath.cjs +0 -42
  15. package/dist/cjs/dictionaryManipulator/getDictionaryValueByKeyPath.cjs.map +0 -1
  16. package/dist/cjs/dictionaryManipulator/getSectionType.cjs +0 -48
  17. package/dist/cjs/dictionaryManipulator/getSectionType.cjs.map +0 -1
  18. package/dist/cjs/dictionaryManipulator/index.cjs +0 -31
  19. package/dist/cjs/dictionaryManipulator/index.cjs.map +0 -1
  20. package/dist/cjs/dictionaryManipulator/isValidReactElement.cjs +0 -30
  21. package/dist/cjs/dictionaryManipulator/isValidReactElement.cjs.map +0 -1
  22. package/dist/cjs/dictionaryManipulator/removeDictionaryValueByKeyPath.cjs +0 -55
  23. package/dist/cjs/dictionaryManipulator/removeDictionaryValueByKeyPath.cjs.map +0 -1
  24. package/dist/cjs/dictionaryManipulator/renameDictionaryValueByKeyPath.cjs +0 -64
  25. package/dist/cjs/dictionaryManipulator/renameDictionaryValueByKeyPath.cjs.map +0 -1
  26. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +0 -61
  27. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +0 -1
  28. package/dist/esm/dictionaryManipulator/getDictionaryValueByKeyPath.mjs +0 -18
  29. package/dist/esm/dictionaryManipulator/getDictionaryValueByKeyPath.mjs.map +0 -1
  30. package/dist/esm/dictionaryManipulator/getSectionType.mjs +0 -26
  31. package/dist/esm/dictionaryManipulator/getSectionType.mjs.map +0 -1
  32. package/dist/esm/dictionaryManipulator/index.mjs +0 -6
  33. package/dist/esm/dictionaryManipulator/index.mjs.map +0 -1
  34. package/dist/esm/dictionaryManipulator/isValidReactElement.mjs +0 -6
  35. package/dist/esm/dictionaryManipulator/isValidReactElement.mjs.map +0 -1
  36. package/dist/esm/dictionaryManipulator/removeDictionaryValueByKeyPath.mjs +0 -31
  37. package/dist/esm/dictionaryManipulator/removeDictionaryValueByKeyPath.mjs.map +0 -1
  38. package/dist/esm/dictionaryManipulator/renameDictionaryValueByKeyPath.mjs +0 -40
  39. package/dist/esm/dictionaryManipulator/renameDictionaryValueByKeyPath.mjs.map +0 -1
  40. package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts +0 -3
  41. package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts.map +0 -1
  42. package/dist/types/dictionaryManipulator/getDictionaryValueByKeyPath.d.ts +0 -3
  43. package/dist/types/dictionaryManipulator/getDictionaryValueByKeyPath.d.ts.map +0 -1
  44. package/dist/types/dictionaryManipulator/getSectionType.d.ts +0 -3
  45. package/dist/types/dictionaryManipulator/getSectionType.d.ts.map +0 -1
  46. package/dist/types/dictionaryManipulator/index.d.ts +0 -6
  47. package/dist/types/dictionaryManipulator/index.d.ts.map +0 -1
  48. package/dist/types/dictionaryManipulator/isValidReactElement.d.ts +0 -9
  49. package/dist/types/dictionaryManipulator/isValidReactElement.d.ts.map +0 -1
  50. package/dist/types/dictionaryManipulator/removeDictionaryValueByKeyPath.d.ts +0 -3
  51. package/dist/types/dictionaryManipulator/removeDictionaryValueByKeyPath.d.ts.map +0 -1
  52. package/dist/types/dictionaryManipulator/renameDictionaryValueByKeyPath.d.ts +0 -3
  53. package/dist/types/dictionaryManipulator/renameDictionaryValueByKeyPath.d.ts.map +0 -1
@@ -15,11 +15,9 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
16
  var index_exports = {};
17
17
  module.exports = __toCommonJS(index_exports);
18
- __reExport(index_exports, require('./dictionaryManipulator/index.cjs'), module.exports);
19
18
  __reExport(index_exports, require('./dictionaryStatus.cjs'), module.exports);
20
19
  // Annotate the CommonJS export names for ESM import in node:
21
20
  0 && (module.exports = {
22
- ...require('./dictionaryManipulator/index.cjs'),
23
21
  ...require('./dictionaryStatus.cjs')
24
22
  });
25
23
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './dictionaryStatus';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0CAAd;AACA,0BAAc,+BADd;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryStatus';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,+BAAd;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport { basename, dirname, extname } from 'path';\nimport { getConfiguration, IntlayerConfig } from '@intlayer/config/client';\nimport { DeclarationContent, Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { DictionaryStatus } from '../dictionaryStatus';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary | DeclarationContent,\n config?: IntlayerConfig,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const {\n content: { baseDir },\n } = config ?? getConfiguration();\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = dictionariesRecord[dictionary.key];\n\n if (existingDictionary) {\n const { filePath, ...dictionaryWithoutPath } = dictionary;\n\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, dictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n const isDictionaryJSON = filePath.endsWith('.json');\n\n if (isDictionaryJSON) {\n const contentDeclarationPath = `${baseDir}/${filePath}`;\n // Write the dictionary to the same location of the existing dictionary file\n await fsPromises.writeFile(\n contentDeclarationPath,\n JSON.stringify(\n {\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryWithoutPath,\n },\n null,\n 2\n )\n );\n return { status: 'updated', path: contentDeclarationPath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionariesDirPath = dirname(filePath);\n const dictionariesFileName = basename(filePath, extname(filePath));\n\n const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;\n\n await writeFileWithDirectories(\n newFilePath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n\n return {\n status: 'updated',\n path: newFilePath,\n };\n }\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionary, null, 2)\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await fsPromises.mkdir(dir, { recursive: true });\n }\n\n // Write the file\n await fsPromises.writeFile(filePath, data);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,iBAA4B;AAC5B,kBAA2C;AAC3C,oBAAiD;AAEjD,gCAA+B;AAC/B,wBAAsB;AAGtB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,YACA,QACA,wBACwD;AACxD,QAAM;AAAA,IACJ,SAAS,EAAE,QAAQ;AAAA,EACrB,IAAI,cAAU,gCAAiB;AAE/B,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBAAqB,0BAAAA,QAAmB,WAAW,GAAG;AAE5D,MAAI,oBAAoB;AACtB,UAAM,EAAE,UAAU,GAAG,sBAAsB,IAAI;AAG/C,YAAI,kBAAAC,SAAU,oBAAoB,UAAU,GAAG;AAE7C,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,mBAAmB,SAAS,SAAS,OAAO;AAElD,YAAI,kBAAkB;AACpB,gBAAM,yBAAyB,GAAG,OAAO,IAAI,QAAQ;AAErD,gBAAM,WAAW;AAAA,YACf;AAAA,YACA,KAAK;AAAA,cACH;AAAA,gBACE,SAAS;AAAA,gBACT,GAAG;AAAA,cACL;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AACA,iBAAO,EAAE,QAAQ,WAAW,MAAM,uBAAuB;AAAA,QAC3D,OAAO;AAEL,gBAAM,0BAAsB,qBAAQ,QAAQ;AAC5C,gBAAM,2BAAuB,sBAAS,cAAU,qBAAQ,QAAQ,CAAC;AAEjE,gBAAM,cAAc,GAAG,mBAAmB,IAAI,oBAAoB;AAElE,gBAAM;AAAA,YACJ;AAAA,YACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,UAC/C;AAEA,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM;AAAA,UACR;AAAA,QACF;AAAA,MACF,OAAO;AAEL,cAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAC7E,cAAM;AAAA,UACJ;AAAA,UACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,QAC/C;AACA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,UAAM;AAAA,MACJ;AAAA,MACA,KAAK,UAAU,YAAY,MAAM,CAAC;AAAA,IACpC;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,UAAM,qBAAQ,QAAQ;AAG5B,UAAM,sBAAkB,sBAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACjD;AAGA,UAAM,WAAW,UAAU,UAAU,IAAI;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":["dictionariesRecord","deepEqual"]}
1
+ {"version":3,"sources":["../../../src/server/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport { basename, dirname, extname } from 'path';\nimport { getConfiguration, IntlayerConfig } from '@intlayer/config/client';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { DictionaryStatus } from '../dictionaryStatus';\nimport { Dictionary } from '@intlayer/core';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n config?: IntlayerConfig,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const {\n content: { baseDir },\n } = config ?? getConfiguration();\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = dictionariesRecord[dictionary.key];\n\n if (existingDictionary) {\n const { filePath, ...dictionaryWithoutPath } = dictionary;\n\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, dictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n const isDictionaryJSON = filePath.endsWith('.json');\n\n if (isDictionaryJSON) {\n const contentDeclarationPath = `${baseDir}/${filePath}`;\n // Write the dictionary to the same location of the existing dictionary file\n await fsPromises.writeFile(\n contentDeclarationPath,\n JSON.stringify(\n {\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryWithoutPath,\n },\n null,\n 2\n )\n );\n return { status: 'updated', path: contentDeclarationPath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionariesDirPath = dirname(filePath);\n const dictionariesFileName = basename(filePath, extname(filePath));\n\n const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;\n\n await writeFileWithDirectories(\n newFilePath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n\n return {\n status: 'updated',\n path: newFilePath,\n };\n }\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionary, null, 2)\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await fsPromises.mkdir(dir, { recursive: true });\n }\n\n // Write the file\n await fsPromises.writeFile(filePath, data);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,iBAA4B;AAC5B,kBAA2C;AAC3C,oBAAiD;AACjD,gCAA+B;AAC/B,wBAAsB;AAItB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,YACA,QACA,wBACwD;AACxD,QAAM;AAAA,IACJ,SAAS,EAAE,QAAQ;AAAA,EACrB,IAAI,cAAU,gCAAiB;AAE/B,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBAAqB,0BAAAA,QAAmB,WAAW,GAAG;AAE5D,MAAI,oBAAoB;AACtB,UAAM,EAAE,UAAU,GAAG,sBAAsB,IAAI;AAG/C,YAAI,kBAAAC,SAAU,oBAAoB,UAAU,GAAG;AAE7C,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,mBAAmB,SAAS,SAAS,OAAO;AAElD,YAAI,kBAAkB;AACpB,gBAAM,yBAAyB,GAAG,OAAO,IAAI,QAAQ;AAErD,gBAAM,WAAW;AAAA,YACf;AAAA,YACA,KAAK;AAAA,cACH;AAAA,gBACE,SAAS;AAAA,gBACT,GAAG;AAAA,cACL;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AACA,iBAAO,EAAE,QAAQ,WAAW,MAAM,uBAAuB;AAAA,QAC3D,OAAO;AAEL,gBAAM,0BAAsB,qBAAQ,QAAQ;AAC5C,gBAAM,2BAAuB,sBAAS,cAAU,qBAAQ,QAAQ,CAAC;AAEjE,gBAAM,cAAc,GAAG,mBAAmB,IAAI,oBAAoB;AAElE,gBAAM;AAAA,YACJ;AAAA,YACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,UAC/C;AAEA,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM;AAAA,UACR;AAAA,QACF;AAAA,MACF,OAAO;AAEL,cAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAC7E,cAAM;AAAA,UACJ;AAAA,UACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,QAC/C;AACA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,UAAM;AAAA,MACJ;AAAA,MACA,KAAK,UAAU,YAAY,MAAM,CAAC;AAAA,IACpC;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,UAAM,qBAAQ,QAAQ;AAG5B,UAAM,sBAAkB,sBAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACjD;AAGA,UAAM,WAAW,UAAU,UAAU,IAAI;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":["dictionariesRecord","deepEqual"]}
@@ -1,3 +1,2 @@
1
- export * from "./dictionaryManipulator/index.mjs";
2
1
  export * from "./dictionaryStatus.mjs";
3
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './dictionaryStatus';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryStatus';\n"],"mappings":"AAAA,cAAc;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport { basename, dirname, extname } from 'path';\nimport { getConfiguration, IntlayerConfig } from '@intlayer/config/client';\nimport { DeclarationContent, Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { DictionaryStatus } from '../dictionaryStatus';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary | DeclarationContent,\n config?: IntlayerConfig,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const {\n content: { baseDir },\n } = config ?? getConfiguration();\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = dictionariesRecord[dictionary.key];\n\n if (existingDictionary) {\n const { filePath, ...dictionaryWithoutPath } = dictionary;\n\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, dictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n const isDictionaryJSON = filePath.endsWith('.json');\n\n if (isDictionaryJSON) {\n const contentDeclarationPath = `${baseDir}/${filePath}`;\n // Write the dictionary to the same location of the existing dictionary file\n await fsPromises.writeFile(\n contentDeclarationPath,\n JSON.stringify(\n {\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryWithoutPath,\n },\n null,\n 2\n )\n );\n return { status: 'updated', path: contentDeclarationPath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionariesDirPath = dirname(filePath);\n const dictionariesFileName = basename(filePath, extname(filePath));\n\n const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;\n\n await writeFileWithDirectories(\n newFilePath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n\n return {\n status: 'updated',\n path: newFilePath,\n };\n }\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionary, null, 2)\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await fsPromises.mkdir(dir, { recursive: true });\n }\n\n // Write the file\n await fsPromises.writeFile(filePath, data);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,YAAY,gBAAgB;AAC5B,SAAS,UAAU,SAAS,eAAe;AAC3C,SAAS,wBAAwC;AAEjD,OAAO,wBAAwB;AAC/B,OAAO,eAAe;AAGtB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,YACA,QACA,wBACwD;AACxD,QAAM;AAAA,IACJ,SAAS,EAAE,QAAQ;AAAA,EACrB,IAAI,UAAU,iBAAiB;AAE/B,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBAAqB,mBAAmB,WAAW,GAAG;AAE5D,MAAI,oBAAoB;AACtB,UAAM,EAAE,UAAU,GAAG,sBAAsB,IAAI;AAG/C,QAAI,UAAU,oBAAoB,UAAU,GAAG;AAE7C,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,mBAAmB,SAAS,SAAS,OAAO;AAElD,YAAI,kBAAkB;AACpB,gBAAM,yBAAyB,GAAG,OAAO,IAAI,QAAQ;AAErD,gBAAM,WAAW;AAAA,YACf;AAAA,YACA,KAAK;AAAA,cACH;AAAA,gBACE,SAAS;AAAA,gBACT,GAAG;AAAA,cACL;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AACA,iBAAO,EAAE,QAAQ,WAAW,MAAM,uBAAuB;AAAA,QAC3D,OAAO;AAEL,gBAAM,sBAAsB,QAAQ,QAAQ;AAC5C,gBAAM,uBAAuB,SAAS,UAAU,QAAQ,QAAQ,CAAC;AAEjE,gBAAM,cAAc,GAAG,mBAAmB,IAAI,oBAAoB;AAElE,gBAAM;AAAA,YACJ;AAAA,YACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,UAC/C;AAEA,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM;AAAA,UACR;AAAA,QACF;AAAA,MACF,OAAO;AAEL,cAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAC7E,cAAM;AAAA,UACJ;AAAA,UACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,QAC/C;AACA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,UAAM;AAAA,MACJ;AAAA,MACA,KAAK,UAAU,YAAY,MAAM,CAAC;AAAA,IACpC;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,MAAM,QAAQ,QAAQ;AAG5B,UAAM,kBAAkB,WAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACjD;AAGA,UAAM,WAAW,UAAU,UAAU,IAAI;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport { basename, dirname, extname } from 'path';\nimport { getConfiguration, IntlayerConfig } from '@intlayer/config/client';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { DictionaryStatus } from '../dictionaryStatus';\nimport { Dictionary } from '@intlayer/core';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n config?: IntlayerConfig,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const {\n content: { baseDir },\n } = config ?? getConfiguration();\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = dictionariesRecord[dictionary.key];\n\n if (existingDictionary) {\n const { filePath, ...dictionaryWithoutPath } = dictionary;\n\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, dictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n const isDictionaryJSON = filePath.endsWith('.json');\n\n if (isDictionaryJSON) {\n const contentDeclarationPath = `${baseDir}/${filePath}`;\n // Write the dictionary to the same location of the existing dictionary file\n await fsPromises.writeFile(\n contentDeclarationPath,\n JSON.stringify(\n {\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryWithoutPath,\n },\n null,\n 2\n )\n );\n return { status: 'updated', path: contentDeclarationPath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionariesDirPath = dirname(filePath);\n const dictionariesFileName = basename(filePath, extname(filePath));\n\n const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;\n\n await writeFileWithDirectories(\n newFilePath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n\n return {\n status: 'updated',\n path: newFilePath,\n };\n }\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionary, null, 2)\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await fsPromises.mkdir(dir, { recursive: true });\n }\n\n // Write the file\n await fsPromises.writeFile(filePath, data);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,YAAY,gBAAgB;AAC5B,SAAS,UAAU,SAAS,eAAe;AAC3C,SAAS,wBAAwC;AACjD,OAAO,wBAAwB;AAC/B,OAAO,eAAe;AAItB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,YACA,QACA,wBACwD;AACxD,QAAM;AAAA,IACJ,SAAS,EAAE,QAAQ;AAAA,EACrB,IAAI,UAAU,iBAAiB;AAE/B,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBAAqB,mBAAmB,WAAW,GAAG;AAE5D,MAAI,oBAAoB;AACtB,UAAM,EAAE,UAAU,GAAG,sBAAsB,IAAI;AAG/C,QAAI,UAAU,oBAAoB,UAAU,GAAG;AAE7C,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,mBAAmB,SAAS,SAAS,OAAO;AAElD,YAAI,kBAAkB;AACpB,gBAAM,yBAAyB,GAAG,OAAO,IAAI,QAAQ;AAErD,gBAAM,WAAW;AAAA,YACf;AAAA,YACA,KAAK;AAAA,cACH;AAAA,gBACE,SAAS;AAAA,gBACT,GAAG;AAAA,cACL;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AACA,iBAAO,EAAE,QAAQ,WAAW,MAAM,uBAAuB;AAAA,QAC3D,OAAO;AAEL,gBAAM,sBAAsB,QAAQ,QAAQ;AAC5C,gBAAM,uBAAuB,SAAS,UAAU,QAAQ,QAAQ,CAAC;AAEjE,gBAAM,cAAc,GAAG,mBAAmB,IAAI,oBAAoB;AAElE,gBAAM;AAAA,YACJ;AAAA,YACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,UAC/C;AAEA,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM;AAAA,UACR;AAAA,QACF;AAAA,MACF,OAAO;AAEL,cAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAC7E,cAAM;AAAA,UACJ;AAAA,UACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,QAC/C;AACA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,UAAM;AAAA,MACJ;AAAA,MACA,KAAK,UAAU,YAAY,MAAM,CAAC;AAAA,IACpC;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,MAAM,QAAQ,QAAQ;AAG5B,UAAM,kBAAkB,WAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACjD;AAGA,UAAM,WAAW,UAAU,UAAU,IAAI;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":[]}
@@ -1,3 +1,2 @@
1
- export * from './dictionaryManipulator/index';
2
1
  export * from './dictionaryStatus';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { IntlayerConfig } from '@intlayer/config/client';
2
- import { DeclarationContent, Dictionary } from '@intlayer/core';
3
2
  import { DictionaryStatus } from '../dictionaryStatus';
4
- export declare const writeContentDeclaration: (dictionary: Dictionary | DeclarationContent, config?: IntlayerConfig, newDictionariesPath?: string) => Promise<{
3
+ import { Dictionary } from '@intlayer/core';
4
+ export declare const writeContentDeclaration: (dictionary: Dictionary, config?: IntlayerConfig, newDictionariesPath?: string) => Promise<{
5
5
  status: DictionaryStatus;
6
6
  path: string;
7
7
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"writeContentDeclaration.d.ts","sourceRoot":"","sources":["../../../src/server/writeContentDeclaration.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAIvD,eAAO,MAAM,uBAAuB,eACtB,UAAU,GAAG,kBAAkB,WAClC,cAAc,wBACD,MAAM,KAC3B,OAAO,CAAC;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAoFpD,CAAC"}
1
+ {"version":3,"file":"writeContentDeclaration.d.ts","sourceRoot":"","sources":["../../../src/server/writeContentDeclaration.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,eAAO,MAAM,uBAAuB,eACtB,UAAU,WACb,cAAc,wBACD,MAAM,KAC3B,OAAO,CAAC;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAoFpD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/editor",
3
- "version": "4.1.11",
3
+ "version": "5.0.0",
4
4
  "private": false,
5
5
  "description": "Provides the utilities to interface the application with the Intlayer editor and manipulate dictionaries",
6
6
  "keywords": [
@@ -57,9 +57,9 @@
57
57
  ],
58
58
  "dependencies": {
59
59
  "deep-equal": "^2.2.3",
60
- "@intlayer/config": "4.1.11",
61
- "@intlayer/core": "4.1.11",
62
- "@intlayer/dictionaries-entry": "4.1.11"
60
+ "@intlayer/config": "5.0.0",
61
+ "@intlayer/core": "5.0.0",
62
+ "@intlayer/dictionaries-entry": "5.0.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/deep-equal": "^1.0.4",
@@ -78,9 +78,9 @@
78
78
  "@utils/tsup-config": "1.0.4"
79
79
  },
80
80
  "peerDependencies": {
81
- "@intlayer/config": "4.1.11",
82
- "@intlayer/dictionaries-entry": "4.1.11",
83
- "@intlayer/core": "4.1.11"
81
+ "@intlayer/config": "5.0.0",
82
+ "@intlayer/core": "5.0.0",
83
+ "@intlayer/dictionaries-entry": "5.0.0"
84
84
  },
85
85
  "engines": {
86
86
  "node": ">=14.18"
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var editDictionaryByKeyPath_exports = {};
20
- __export(editDictionaryByKeyPath_exports, {
21
- editDictionaryByKeyPath: () => editDictionaryByKeyPath
22
- });
23
- module.exports = __toCommonJS(editDictionaryByKeyPath_exports);
24
- var import_core = require("@intlayer/core");
25
- const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
26
- let currentValue = dictionaryContent;
27
- let parentValue = null;
28
- let lastKeys = [];
29
- for (const keyObj of keyPath) {
30
- parentValue = currentValue;
31
- if (keyObj.type === import_core.NodeType.Object) {
32
- lastKeys = [keyObj.key];
33
- if (!currentValue[keyObj.key]) {
34
- currentValue = {
35
- ...currentValue,
36
- [keyObj.key]: {}
37
- };
38
- }
39
- currentValue = currentValue[keyObj.key];
40
- } else if (keyObj.type === import_core.NodeType.Array) {
41
- lastKeys = [keyObj.key];
42
- if (!currentValue[keyObj.key]) {
43
- currentValue[keyObj.key] = {};
44
- }
45
- currentValue = currentValue[keyObj.key];
46
- } else if (keyObj.type === import_core.NodeType.Translation) {
47
- lastKeys = [import_core.NodeType.Translation, keyObj.key];
48
- if (!currentValue[import_core.NodeType.Translation]) {
49
- currentValue[import_core.NodeType.Translation] = {
50
- ...currentValue[import_core.NodeType.Translation],
51
- [keyObj.key]: newValue
52
- };
53
- }
54
- currentValue = currentValue[import_core.NodeType.Translation][keyObj.key];
55
- } else if (keyObj.type === import_core.NodeType.Enumeration) {
56
- lastKeys = [import_core.NodeType.Enumeration, keyObj.key];
57
- if (!currentValue[import_core.NodeType.Enumeration]) {
58
- currentValue[import_core.NodeType.Enumeration] = {
59
- ...currentValue[import_core.NodeType.Enumeration],
60
- [keyObj.key]: newValue
61
- };
62
- }
63
- currentValue = currentValue[import_core.NodeType.Enumeration][keyObj.key];
64
- }
65
- }
66
- if (parentValue && lastKeys.length > 0) {
67
- for (const key of lastKeys.slice(0, -1)) {
68
- parentValue = parentValue[key];
69
- }
70
- if (
71
- // Remove the field if the new value is undefined
72
- typeof newValue === "undefined"
73
- ) {
74
- delete parentValue[lastKeys[lastKeys.length - 1]];
75
- } else {
76
- parentValue[lastKeys[lastKeys.length - 1]] = newValue;
77
- }
78
- }
79
- return dictionaryContent;
80
- };
81
- // Annotate the CommonJS export names for ESM import in node:
82
- 0 && (module.exports = {
83
- editDictionaryByKeyPath
84
- });
85
- //# sourceMappingURL=editDictionaryByKeyPath.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type DictionaryValue, type KeyPath, NodeType } from '@intlayer/core';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[],\n newValue: DictionaryValue\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue = {\n ...currentValue,\n [keyObj.key]: {},\n };\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKeys = [NodeType.Translation, keyObj.key];\n\n if (!currentValue[NodeType.Translation]) {\n currentValue[NodeType.Translation] = {\n ...currentValue[NodeType.Translation],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKeys = [NodeType.Enumeration, keyObj.key];\n\n if (!currentValue[NodeType.Enumeration]) {\n currentValue[NodeType.Enumeration] = {\n ...currentValue[NodeType.Enumeration],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n // Assign the new value to the last key of the parent\n if (parentValue && lastKeys.length > 0) {\n for (const key of lastKeys.slice(0, -1)) {\n parentValue = parentValue[key];\n }\n if (\n // Remove the field if the new value is undefined\n typeof newValue === 'undefined'\n ) {\n delete parentValue[lastKeys[lastKeys.length - 1]];\n } else {\n parentValue[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAA6D;AAItD,MAAM,0BAA0B,CACrC,mBACA,SACA,aACoB;AACpB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,WAA0B,CAAC;AAE/B,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,qBAAS,QAAQ;AACnC,iBAAW,CAAC,OAAO,GAAG;AAEtB,UAAI,CAAC,aAAa,OAAO,GAAG,GAAG;AAC7B,uBAAe;AAAA,UACb,GAAG;AAAA,UACH,CAAC,OAAO,GAAG,GAAG,CAAC;AAAA,QACjB;AAAA,MACF;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,qBAAS,OAAO;AACzC,iBAAW,CAAC,OAAO,GAAG;AAEtB,UAAI,CAAC,aAAa,OAAO,GAAG,GAAG;AAC7B,qBAAa,OAAO,GAAG,IAAI,CAAC;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,iBAAW,CAAC,qBAAS,aAAa,OAAO,GAAG;AAE5C,UAAI,CAAC,aAAa,qBAAS,WAAW,GAAG;AACvC,qBAAa,qBAAS,WAAW,IAAI;AAAA,UACnC,GAAG,aAAa,qBAAS,WAAW;AAAA,UACpC,CAAC,OAAO,GAAG,GAAG;AAAA,QAChB;AAAA,MACF;AACA,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,iBAAW,CAAC,qBAAS,aAAa,OAAO,GAAG;AAE5C,UAAI,CAAC,aAAa,qBAAS,WAAW,GAAG;AACvC,qBAAa,qBAAS,WAAW,IAAI;AAAA,UACnC,GAAG,aAAa,qBAAS,WAAW;AAAA,UACpC,CAAC,OAAO,GAAG,GAAG;AAAA,QAChB;AAAA,MACF;AACA,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D;AAAA,EACF;AAGA,MAAI,eAAe,SAAS,SAAS,GAAG;AACtC,eAAW,OAAO,SAAS,MAAM,GAAG,EAAE,GAAG;AACvC,oBAAc,YAAY,GAAG;AAAA,IAC/B;AACA;AAAA;AAAA,MAEE,OAAO,aAAa;AAAA,MACpB;AACA,aAAO,YAAY,SAAS,SAAS,SAAS,CAAC,CAAC;AAAA,IAClD,OAAO;AACL,kBAAY,SAAS,SAAS,SAAS,CAAC,CAAC,IAAI;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var getDictionaryValueByKeyPath_exports = {};
20
- __export(getDictionaryValueByKeyPath_exports, {
21
- getDictionaryValueByKeyPath: () => getDictionaryValueByKeyPath
22
- });
23
- module.exports = __toCommonJS(getDictionaryValueByKeyPath_exports);
24
- var import_core = require("@intlayer/core");
25
- const getDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
26
- let currentValue = JSON.parse(JSON.stringify(dictionaryContent ?? {}));
27
- for (const keyObj of keyPath) {
28
- if (keyObj.type === import_core.NodeType.Object || keyObj.type === import_core.NodeType.Array) {
29
- currentValue = currentValue?.[keyObj.key];
30
- } else if (keyObj.type === import_core.NodeType.Translation) {
31
- currentValue = currentValue?.[import_core.NodeType.Translation][keyObj.key];
32
- } else if (keyObj.type === import_core.NodeType.Enumeration) {
33
- currentValue = currentValue?.[import_core.NodeType.Enumeration][keyObj.key];
34
- }
35
- }
36
- return currentValue;
37
- };
38
- // Annotate the CommonJS export names for ESM import in node:
39
- 0 && (module.exports = {
40
- getDictionaryValueByKeyPath
41
- });
42
- //# sourceMappingURL=getDictionaryValueByKeyPath.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/getDictionaryValueByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type DictionaryValue, type KeyPath, NodeType } from '@intlayer/core';\n\nexport const getDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = JSON.parse(JSON.stringify(dictionaryContent ?? {}));\n\n for (const keyObj of keyPath) {\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];\n }\n }\n\n return currentValue as DictionaryValue;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAA6D;AAEtD,MAAM,8BAA8B,CACzC,mBACA,YACoB;AACpB,MAAI,eAAoB,KAAK,MAAM,KAAK,UAAU,qBAAqB,CAAC,CAAC,CAAC;AAE1E,aAAW,UAAU,SAAS;AAC5B,QAAI,OAAO,SAAS,qBAAS,UAAU,OAAO,SAAS,qBAAS,OAAO;AACrE,qBAAe,eAAe,OAAO,GAAG;AAAA,IAC1C,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,qBAAe,eAAe,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,qBAAe,eAAe,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var getSectionType_exports = {};
20
- __export(getSectionType_exports, {
21
- getSectionType: () => getSectionType
22
- });
23
- module.exports = __toCommonJS(getSectionType_exports);
24
- var import_core = require("@intlayer/core");
25
- var import_isValidReactElement = require('./isValidReactElement.cjs');
26
- const getSectionType = (section) => {
27
- if (typeof section === "string") {
28
- return import_core.NodeType.Text;
29
- }
30
- if (section?.nodeType === import_core.NodeType.Translation) {
31
- return import_core.NodeType.Translation;
32
- }
33
- if (section?.nodeType === import_core.NodeType.Enumeration) {
34
- return import_core.NodeType.Enumeration;
35
- }
36
- if (Array.isArray(section)) {
37
- return import_core.NodeType.Array;
38
- }
39
- if ((0, import_isValidReactElement.isValidElement)(section)) {
40
- return import_core.NodeType.ReactNode;
41
- }
42
- return import_core.NodeType.Object;
43
- };
44
- // Annotate the CommonJS export names for ESM import in node:
45
- 0 && (module.exports = {
46
- getSectionType
47
- });
48
- //# sourceMappingURL=getSectionType.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/getSectionType.ts"],"sourcesContent":["import {\n type TranslationContent,\n type EnumerationContent,\n type DictionaryValue,\n NodeType,\n} from '@intlayer/core';\nimport { isValidElement } from './isValidReactElement';\n\nexport const getSectionType = (section: DictionaryValue): NodeType => {\n if (typeof section === 'string') {\n return NodeType.Text;\n }\n\n if (\n (section as TranslationContent<unknown>)?.nodeType === NodeType.Translation\n ) {\n return NodeType.Translation;\n }\n\n if (\n (section as EnumerationContent<unknown>)?.nodeType === NodeType.Enumeration\n ) {\n return NodeType.Enumeration;\n }\n\n if (Array.isArray(section)) {\n return NodeType.Array;\n }\n\n if (isValidElement(section)) {\n return NodeType.ReactNode;\n }\n\n return NodeType.Object;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAKO;AACP,iCAA+B;AAExB,MAAM,iBAAiB,CAAC,YAAuC;AACpE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,qBAAS;AAAA,EAClB;AAEA,MACG,SAAyC,aAAa,qBAAS,aAChE;AACA,WAAO,qBAAS;AAAA,EAClB;AAEA,MACG,SAAyC,aAAa,qBAAS,aAChE;AACA,WAAO,qBAAS;AAAA,EAClB;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO,qBAAS;AAAA,EAClB;AAEA,UAAI,2CAAe,OAAO,GAAG;AAC3B,WAAO,qBAAS;AAAA,EAClB;AAEA,SAAO,qBAAS;AAClB;","names":[]}
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var dictionaryManipulator_exports = {};
17
- module.exports = __toCommonJS(dictionaryManipulator_exports);
18
- __reExport(dictionaryManipulator_exports, require('./editDictionaryByKeyPath.cjs'), module.exports);
19
- __reExport(dictionaryManipulator_exports, require('./getDictionaryValueByKeyPath.cjs'), module.exports);
20
- __reExport(dictionaryManipulator_exports, require('./getSectionType.cjs'), module.exports);
21
- __reExport(dictionaryManipulator_exports, require('./removeDictionaryValueByKeyPath.cjs'), module.exports);
22
- __reExport(dictionaryManipulator_exports, require('./renameDictionaryValueByKeyPath.cjs'), module.exports);
23
- // Annotate the CommonJS export names for ESM import in node:
24
- 0 && (module.exports = {
25
- ...require('./editDictionaryByKeyPath.cjs'),
26
- ...require('./getDictionaryValueByKeyPath.cjs'),
27
- ...require('./getSectionType.cjs'),
28
- ...require('./removeDictionaryValueByKeyPath.cjs'),
29
- ...require('./renameDictionaryValueByKeyPath.cjs')
30
- });
31
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/index.ts"],"sourcesContent":["export * from './editDictionaryByKeyPath';\nexport * from './getDictionaryValueByKeyPath';\nexport * from './getSectionType';\nexport * from './removeDictionaryValueByKeyPath';\nexport * from './renameDictionaryValueByKeyPath';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0CAAc,sCAAd;AACA,0CAAc,0CADd;AAEA,0CAAc,6BAFd;AAGA,0CAAc,6CAHd;AAIA,0CAAc,6CAJd;","names":[]}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var isValidReactElement_exports = {};
20
- __export(isValidReactElement_exports, {
21
- isValidElement: () => isValidElement
22
- });
23
- module.exports = __toCommonJS(isValidReactElement_exports);
24
- const REACT_ELEMENT_TYPE = Symbol.for("react.element");
25
- const isValidElement = (object) => typeof object === "object" && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
26
- // Annotate the CommonJS export names for ESM import in node:
27
- 0 && (module.exports = {
28
- isValidElement
29
- });
30
- //# sourceMappingURL=isValidReactElement.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/isValidReactElement.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nconst REACT_ELEMENT_TYPE = Symbol.for('react.element');\n\n/**\n * Verifies the object is a ReactElement.\n * See https://reactjs.org/docs/react-api.html#isvalidelement\n * @param object\n * @return True if `object` is a ReactElement.\n * @final\n */\n\nexport const isValidElement = (object: any): boolean =>\n typeof object === 'object' &&\n object !== null &&\n object.$$typeof === REACT_ELEMENT_TYPE;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,MAAM,qBAAqB,OAAO,IAAI,eAAe;AAU9C,MAAM,iBAAiB,CAAC,WAC7B,OAAO,WAAW,YAClB,WAAW,QACX,OAAO,aAAa;","names":[]}
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var removeDictionaryValueByKeyPath_exports = {};
20
- __export(removeDictionaryValueByKeyPath_exports, {
21
- removeDictionaryValueByKeyPath: () => removeDictionaryValueByKeyPath
22
- });
23
- module.exports = __toCommonJS(removeDictionaryValueByKeyPath_exports);
24
- var import_core = require("@intlayer/core");
25
- const removeDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
26
- let currentValue = dictionaryContent;
27
- let parentValue = null;
28
- let lastKey = null;
29
- for (const keyObj of keyPath) {
30
- parentValue = currentValue;
31
- if (keyObj.type === import_core.NodeType.Object || keyObj.type === import_core.NodeType.Array) {
32
- lastKey = keyObj.key;
33
- currentValue = currentValue[keyObj.key];
34
- } else if (keyObj.type === import_core.NodeType.Translation) {
35
- lastKey = import_core.NodeType.Translation;
36
- currentValue = currentValue[import_core.NodeType.Translation][keyObj.key];
37
- } else if (keyObj.type === import_core.NodeType.Enumeration) {
38
- lastKey = import_core.NodeType.Enumeration;
39
- currentValue = currentValue[import_core.NodeType.Enumeration][keyObj.key];
40
- }
41
- }
42
- if (parentValue && lastKey !== null) {
43
- if (Array.isArray(parentValue)) {
44
- parentValue.splice(lastKey, 1);
45
- } else {
46
- delete parentValue[lastKey];
47
- }
48
- }
49
- return dictionaryContent;
50
- };
51
- // Annotate the CommonJS export names for ESM import in node:
52
- 0 && (module.exports = {
53
- removeDictionaryValueByKeyPath
54
- });
55
- //# sourceMappingURL=removeDictionaryValueByKeyPath.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/removeDictionaryValueByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { DictionaryValue, KeyPath, NodeType } from '@intlayer/core';\n\nexport const removeDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAmD;AAE5C,MAAM,iCAAiC,CAC5C,mBACA,YACoB;AACpB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,UAAkC;AAEtC,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,qBAAS,UAAU,OAAO,SAAS,qBAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,gBAAU,qBAAS;AACnB,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,gBAAU,qBAAS;AACnB,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D;AAAA,EACF;AAEA,MAAI,eAAe,YAAY,MAAM;AACnC,QAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,kBAAY,OAAO,SAA8B,CAAC;AAAA,IACpD,OAAO;AACL,aAAO,YAAY,OAAO;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,64 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var renameDictionaryValueByKeyPath_exports = {};
20
- __export(renameDictionaryValueByKeyPath_exports, {
21
- renameDictionaryValueByKeyPath: () => renameDictionaryValueByKeyPath
22
- });
23
- module.exports = __toCommonJS(renameDictionaryValueByKeyPath_exports);
24
- var import_core = require("@intlayer/core");
25
- const renameDictionaryValueByKeyPath = (dictionaryContent, newKey, keyPath) => {
26
- let currentValue = dictionaryContent;
27
- let parentValue = null;
28
- let lastKey = null;
29
- for (const keyObj of keyPath) {
30
- parentValue = currentValue;
31
- if (keyObj.type === import_core.NodeType.Object || keyObj.type === import_core.NodeType.Array) {
32
- lastKey = keyObj.key;
33
- currentValue = currentValue[keyObj.key];
34
- } else if (keyObj.type === import_core.NodeType.Translation) {
35
- lastKey = import_core.NodeType.Translation;
36
- currentValue = currentValue[import_core.NodeType.Translation][keyObj.key];
37
- } else if (keyObj.type === import_core.NodeType.Enumeration) {
38
- lastKey = import_core.NodeType.Enumeration;
39
- currentValue = currentValue[import_core.NodeType.Enumeration][keyObj.key];
40
- }
41
- }
42
- if (parentValue && lastKey !== null) {
43
- if (Array.isArray(parentValue)) {
44
- parentValue[lastKey] = currentValue;
45
- } else {
46
- const newParentValue = {};
47
- for (const key of Object.keys(parentValue)) {
48
- if (key === lastKey) {
49
- newParentValue[newKey] = currentValue;
50
- } else {
51
- newParentValue[key] = parentValue[key];
52
- }
53
- }
54
- Object.keys(parentValue).forEach((key) => delete parentValue[key]);
55
- Object.assign(parentValue, newParentValue);
56
- }
57
- }
58
- return dictionaryContent;
59
- };
60
- // Annotate the CommonJS export names for ESM import in node:
61
- 0 && (module.exports = {
62
- renameDictionaryValueByKeyPath
63
- });
64
- //# sourceMappingURL=renameDictionaryValueByKeyPath.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/renameDictionaryValueByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { DictionaryValue, KeyPath, NodeType } from '@intlayer/core';\n\nexport const renameDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n newKey: string | number,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n // Assign the new value to the last key of the parent while preserving the order\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue[lastKey as number] = currentValue;\n } else {\n const newParentValue: any = {};\n for (const key of Object.keys(parentValue)) {\n if (key === lastKey) {\n newParentValue[newKey] = currentValue;\n } else {\n newParentValue[key] = parentValue[key];\n }\n }\n // Replace the contents of parentValue with newParentValue\n Object.keys(parentValue).forEach((key) => delete parentValue[key]);\n Object.assign(parentValue, newParentValue);\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAmD;AAE5C,MAAM,iCAAiC,CAC5C,mBACA,QACA,YACoB;AACpB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,UAAkC;AAEtC,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,qBAAS,UAAU,OAAO,SAAS,qBAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,gBAAU,qBAAS;AACnB,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,gBAAU,qBAAS;AACnB,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D;AAAA,EACF;AAGA,MAAI,eAAe,YAAY,MAAM;AACnC,QAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,kBAAY,OAAiB,IAAI;AAAA,IACnC,OAAO;AACL,YAAM,iBAAsB,CAAC;AAC7B,iBAAW,OAAO,OAAO,KAAK,WAAW,GAAG;AAC1C,YAAI,QAAQ,SAAS;AACnB,yBAAe,MAAM,IAAI;AAAA,QAC3B,OAAO;AACL,yBAAe,GAAG,IAAI,YAAY,GAAG;AAAA,QACvC;AAAA,MACF;AAEA,aAAO,KAAK,WAAW,EAAE,QAAQ,CAAC,QAAQ,OAAO,YAAY,GAAG,CAAC;AACjE,aAAO,OAAO,aAAa,cAAc;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,61 +0,0 @@
1
- import { NodeType } from "@intlayer/core";
2
- const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
3
- let currentValue = dictionaryContent;
4
- let parentValue = null;
5
- let lastKeys = [];
6
- for (const keyObj of keyPath) {
7
- parentValue = currentValue;
8
- if (keyObj.type === NodeType.Object) {
9
- lastKeys = [keyObj.key];
10
- if (!currentValue[keyObj.key]) {
11
- currentValue = {
12
- ...currentValue,
13
- [keyObj.key]: {}
14
- };
15
- }
16
- currentValue = currentValue[keyObj.key];
17
- } else if (keyObj.type === NodeType.Array) {
18
- lastKeys = [keyObj.key];
19
- if (!currentValue[keyObj.key]) {
20
- currentValue[keyObj.key] = {};
21
- }
22
- currentValue = currentValue[keyObj.key];
23
- } else if (keyObj.type === NodeType.Translation) {
24
- lastKeys = [NodeType.Translation, keyObj.key];
25
- if (!currentValue[NodeType.Translation]) {
26
- currentValue[NodeType.Translation] = {
27
- ...currentValue[NodeType.Translation],
28
- [keyObj.key]: newValue
29
- };
30
- }
31
- currentValue = currentValue[NodeType.Translation][keyObj.key];
32
- } else if (keyObj.type === NodeType.Enumeration) {
33
- lastKeys = [NodeType.Enumeration, keyObj.key];
34
- if (!currentValue[NodeType.Enumeration]) {
35
- currentValue[NodeType.Enumeration] = {
36
- ...currentValue[NodeType.Enumeration],
37
- [keyObj.key]: newValue
38
- };
39
- }
40
- currentValue = currentValue[NodeType.Enumeration][keyObj.key];
41
- }
42
- }
43
- if (parentValue && lastKeys.length > 0) {
44
- for (const key of lastKeys.slice(0, -1)) {
45
- parentValue = parentValue[key];
46
- }
47
- if (
48
- // Remove the field if the new value is undefined
49
- typeof newValue === "undefined"
50
- ) {
51
- delete parentValue[lastKeys[lastKeys.length - 1]];
52
- } else {
53
- parentValue[lastKeys[lastKeys.length - 1]] = newValue;
54
- }
55
- }
56
- return dictionaryContent;
57
- };
58
- export {
59
- editDictionaryByKeyPath
60
- };
61
- //# sourceMappingURL=editDictionaryByKeyPath.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type DictionaryValue, type KeyPath, NodeType } from '@intlayer/core';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[],\n newValue: DictionaryValue\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue = {\n ...currentValue,\n [keyObj.key]: {},\n };\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKeys = [NodeType.Translation, keyObj.key];\n\n if (!currentValue[NodeType.Translation]) {\n currentValue[NodeType.Translation] = {\n ...currentValue[NodeType.Translation],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKeys = [NodeType.Enumeration, keyObj.key];\n\n if (!currentValue[NodeType.Enumeration]) {\n currentValue[NodeType.Enumeration] = {\n ...currentValue[NodeType.Enumeration],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n // Assign the new value to the last key of the parent\n if (parentValue && lastKeys.length > 0) {\n for (const key of lastKeys.slice(0, -1)) {\n parentValue = parentValue[key];\n }\n if (\n // Remove the field if the new value is undefined\n typeof newValue === 'undefined'\n ) {\n delete parentValue[lastKeys[lastKeys.length - 1]];\n } else {\n parentValue[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":"AACA,SAA6C,gBAAgB;AAItD,MAAM,0BAA0B,CACrC,mBACA,SACA,aACoB;AACpB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,WAA0B,CAAC;AAE/B,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,SAAS,QAAQ;AACnC,iBAAW,CAAC,OAAO,GAAG;AAEtB,UAAI,CAAC,aAAa,OAAO,GAAG,GAAG;AAC7B,uBAAe;AAAA,UACb,GAAG;AAAA,UACH,CAAC,OAAO,GAAG,GAAG,CAAC;AAAA,QACjB;AAAA,MACF;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,SAAS,OAAO;AACzC,iBAAW,CAAC,OAAO,GAAG;AAEtB,UAAI,CAAC,aAAa,OAAO,GAAG,GAAG;AAC7B,qBAAa,OAAO,GAAG,IAAI,CAAC;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,iBAAW,CAAC,SAAS,aAAa,OAAO,GAAG;AAE5C,UAAI,CAAC,aAAa,SAAS,WAAW,GAAG;AACvC,qBAAa,SAAS,WAAW,IAAI;AAAA,UACnC,GAAG,aAAa,SAAS,WAAW;AAAA,UACpC,CAAC,OAAO,GAAG,GAAG;AAAA,QAChB;AAAA,MACF;AACA,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,iBAAW,CAAC,SAAS,aAAa,OAAO,GAAG;AAE5C,UAAI,CAAC,aAAa,SAAS,WAAW,GAAG;AACvC,qBAAa,SAAS,WAAW,IAAI;AAAA,UACnC,GAAG,aAAa,SAAS,WAAW;AAAA,UACpC,CAAC,OAAO,GAAG,GAAG;AAAA,QAChB;AAAA,MACF;AACA,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D;AAAA,EACF;AAGA,MAAI,eAAe,SAAS,SAAS,GAAG;AACtC,eAAW,OAAO,SAAS,MAAM,GAAG,EAAE,GAAG;AACvC,oBAAc,YAAY,GAAG;AAAA,IAC/B;AACA;AAAA;AAAA,MAEE,OAAO,aAAa;AAAA,MACpB;AACA,aAAO,YAAY,SAAS,SAAS,SAAS,CAAC,CAAC;AAAA,IAClD,OAAO;AACL,kBAAY,SAAS,SAAS,SAAS,CAAC,CAAC,IAAI;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,18 +0,0 @@
1
- import { NodeType } from "@intlayer/core";
2
- const getDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
3
- let currentValue = JSON.parse(JSON.stringify(dictionaryContent ?? {}));
4
- for (const keyObj of keyPath) {
5
- if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
6
- currentValue = currentValue?.[keyObj.key];
7
- } else if (keyObj.type === NodeType.Translation) {
8
- currentValue = currentValue?.[NodeType.Translation][keyObj.key];
9
- } else if (keyObj.type === NodeType.Enumeration) {
10
- currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];
11
- }
12
- }
13
- return currentValue;
14
- };
15
- export {
16
- getDictionaryValueByKeyPath
17
- };
18
- //# sourceMappingURL=getDictionaryValueByKeyPath.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/getDictionaryValueByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type DictionaryValue, type KeyPath, NodeType } from '@intlayer/core';\n\nexport const getDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = JSON.parse(JSON.stringify(dictionaryContent ?? {}));\n\n for (const keyObj of keyPath) {\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];\n }\n }\n\n return currentValue as DictionaryValue;\n};\n"],"mappings":"AACA,SAA6C,gBAAgB;AAEtD,MAAM,8BAA8B,CACzC,mBACA,YACoB;AACpB,MAAI,eAAoB,KAAK,MAAM,KAAK,UAAU,qBAAqB,CAAC,CAAC,CAAC;AAE1E,aAAW,UAAU,SAAS;AAC5B,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,qBAAe,eAAe,OAAO,GAAG;AAAA,IAC1C,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,qBAAe,eAAe,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,qBAAe,eAAe,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,26 +0,0 @@
1
- import {
2
- NodeType
3
- } from "@intlayer/core";
4
- import { isValidElement } from "./isValidReactElement.mjs";
5
- const getSectionType = (section) => {
6
- if (typeof section === "string") {
7
- return NodeType.Text;
8
- }
9
- if (section?.nodeType === NodeType.Translation) {
10
- return NodeType.Translation;
11
- }
12
- if (section?.nodeType === NodeType.Enumeration) {
13
- return NodeType.Enumeration;
14
- }
15
- if (Array.isArray(section)) {
16
- return NodeType.Array;
17
- }
18
- if (isValidElement(section)) {
19
- return NodeType.ReactNode;
20
- }
21
- return NodeType.Object;
22
- };
23
- export {
24
- getSectionType
25
- };
26
- //# sourceMappingURL=getSectionType.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/getSectionType.ts"],"sourcesContent":["import {\n type TranslationContent,\n type EnumerationContent,\n type DictionaryValue,\n NodeType,\n} from '@intlayer/core';\nimport { isValidElement } from './isValidReactElement';\n\nexport const getSectionType = (section: DictionaryValue): NodeType => {\n if (typeof section === 'string') {\n return NodeType.Text;\n }\n\n if (\n (section as TranslationContent<unknown>)?.nodeType === NodeType.Translation\n ) {\n return NodeType.Translation;\n }\n\n if (\n (section as EnumerationContent<unknown>)?.nodeType === NodeType.Enumeration\n ) {\n return NodeType.Enumeration;\n }\n\n if (Array.isArray(section)) {\n return NodeType.Array;\n }\n\n if (isValidElement(section)) {\n return NodeType.ReactNode;\n }\n\n return NodeType.Object;\n};\n"],"mappings":"AAAA;AAAA,EAIE;AAAA,OACK;AACP,SAAS,sBAAsB;AAExB,MAAM,iBAAiB,CAAC,YAAuC;AACpE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,SAAS;AAAA,EAClB;AAEA,MACG,SAAyC,aAAa,SAAS,aAChE;AACA,WAAO,SAAS;AAAA,EAClB;AAEA,MACG,SAAyC,aAAa,SAAS,aAChE;AACA,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,eAAe,OAAO,GAAG;AAC3B,WAAO,SAAS;AAAA,EAClB;AAEA,SAAO,SAAS;AAClB;","names":[]}
@@ -1,6 +0,0 @@
1
- export * from "./editDictionaryByKeyPath.mjs";
2
- export * from "./getDictionaryValueByKeyPath.mjs";
3
- export * from "./getSectionType.mjs";
4
- export * from "./removeDictionaryValueByKeyPath.mjs";
5
- export * from "./renameDictionaryValueByKeyPath.mjs";
6
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/index.ts"],"sourcesContent":["export * from './editDictionaryByKeyPath';\nexport * from './getDictionaryValueByKeyPath';\nexport * from './getSectionType';\nexport * from './removeDictionaryValueByKeyPath';\nexport * from './renameDictionaryValueByKeyPath';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -1,6 +0,0 @@
1
- const REACT_ELEMENT_TYPE = Symbol.for("react.element");
2
- const isValidElement = (object) => typeof object === "object" && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
3
- export {
4
- isValidElement
5
- };
6
- //# sourceMappingURL=isValidReactElement.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/isValidReactElement.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nconst REACT_ELEMENT_TYPE = Symbol.for('react.element');\n\n/**\n * Verifies the object is a ReactElement.\n * See https://reactjs.org/docs/react-api.html#isvalidelement\n * @param object\n * @return True if `object` is a ReactElement.\n * @final\n */\n\nexport const isValidElement = (object: any): boolean =>\n typeof object === 'object' &&\n object !== null &&\n object.$$typeof === REACT_ELEMENT_TYPE;\n"],"mappings":"AACA,MAAM,qBAAqB,OAAO,IAAI,eAAe;AAU9C,MAAM,iBAAiB,CAAC,WAC7B,OAAO,WAAW,YAClB,WAAW,QACX,OAAO,aAAa;","names":[]}
@@ -1,31 +0,0 @@
1
- import { NodeType } from "@intlayer/core";
2
- const removeDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
3
- let currentValue = dictionaryContent;
4
- let parentValue = null;
5
- let lastKey = null;
6
- for (const keyObj of keyPath) {
7
- parentValue = currentValue;
8
- if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
9
- lastKey = keyObj.key;
10
- currentValue = currentValue[keyObj.key];
11
- } else if (keyObj.type === NodeType.Translation) {
12
- lastKey = NodeType.Translation;
13
- currentValue = currentValue[NodeType.Translation][keyObj.key];
14
- } else if (keyObj.type === NodeType.Enumeration) {
15
- lastKey = NodeType.Enumeration;
16
- currentValue = currentValue[NodeType.Enumeration][keyObj.key];
17
- }
18
- }
19
- if (parentValue && lastKey !== null) {
20
- if (Array.isArray(parentValue)) {
21
- parentValue.splice(lastKey, 1);
22
- } else {
23
- delete parentValue[lastKey];
24
- }
25
- }
26
- return dictionaryContent;
27
- };
28
- export {
29
- removeDictionaryValueByKeyPath
30
- };
31
- //# sourceMappingURL=removeDictionaryValueByKeyPath.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/removeDictionaryValueByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { DictionaryValue, KeyPath, NodeType } from '@intlayer/core';\n\nexport const removeDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":"AAEA,SAAmC,gBAAgB;AAE5C,MAAM,iCAAiC,CAC5C,mBACA,YACoB;AACpB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,UAAkC;AAEtC,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D;AAAA,EACF;AAEA,MAAI,eAAe,YAAY,MAAM;AACnC,QAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,kBAAY,OAAO,SAA8B,CAAC;AAAA,IACpD,OAAO;AACL,aAAO,YAAY,OAAO;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,40 +0,0 @@
1
- import { NodeType } from "@intlayer/core";
2
- const renameDictionaryValueByKeyPath = (dictionaryContent, newKey, keyPath) => {
3
- let currentValue = dictionaryContent;
4
- let parentValue = null;
5
- let lastKey = null;
6
- for (const keyObj of keyPath) {
7
- parentValue = currentValue;
8
- if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
9
- lastKey = keyObj.key;
10
- currentValue = currentValue[keyObj.key];
11
- } else if (keyObj.type === NodeType.Translation) {
12
- lastKey = NodeType.Translation;
13
- currentValue = currentValue[NodeType.Translation][keyObj.key];
14
- } else if (keyObj.type === NodeType.Enumeration) {
15
- lastKey = NodeType.Enumeration;
16
- currentValue = currentValue[NodeType.Enumeration][keyObj.key];
17
- }
18
- }
19
- if (parentValue && lastKey !== null) {
20
- if (Array.isArray(parentValue)) {
21
- parentValue[lastKey] = currentValue;
22
- } else {
23
- const newParentValue = {};
24
- for (const key of Object.keys(parentValue)) {
25
- if (key === lastKey) {
26
- newParentValue[newKey] = currentValue;
27
- } else {
28
- newParentValue[key] = parentValue[key];
29
- }
30
- }
31
- Object.keys(parentValue).forEach((key) => delete parentValue[key]);
32
- Object.assign(parentValue, newParentValue);
33
- }
34
- }
35
- return dictionaryContent;
36
- };
37
- export {
38
- renameDictionaryValueByKeyPath
39
- };
40
- //# sourceMappingURL=renameDictionaryValueByKeyPath.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/renameDictionaryValueByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { DictionaryValue, KeyPath, NodeType } from '@intlayer/core';\n\nexport const renameDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n newKey: string | number,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n // Assign the new value to the last key of the parent while preserving the order\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue[lastKey as number] = currentValue;\n } else {\n const newParentValue: any = {};\n for (const key of Object.keys(parentValue)) {\n if (key === lastKey) {\n newParentValue[newKey] = currentValue;\n } else {\n newParentValue[key] = parentValue[key];\n }\n }\n // Replace the contents of parentValue with newParentValue\n Object.keys(parentValue).forEach((key) => delete parentValue[key]);\n Object.assign(parentValue, newParentValue);\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":"AAEA,SAAmC,gBAAgB;AAE5C,MAAM,iCAAiC,CAC5C,mBACA,QACA,YACoB;AACpB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,UAAkC;AAEtC,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D;AAAA,EACF;AAGA,MAAI,eAAe,YAAY,MAAM;AACnC,QAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,kBAAY,OAAiB,IAAI;AAAA,IACnC,OAAO;AACL,YAAM,iBAAsB,CAAC;AAC7B,iBAAW,OAAO,OAAO,KAAK,WAAW,GAAG;AAC1C,YAAI,QAAQ,SAAS;AACnB,yBAAe,MAAM,IAAI;AAAA,QAC3B,OAAO;AACL,yBAAe,GAAG,IAAI,YAAY,GAAG;AAAA,QACvC;AAAA,MACF;AAEA,aAAO,KAAK,WAAW,EAAE,QAAQ,CAAC,QAAQ,OAAO,YAAY,GAAG,CAAC;AACjE,aAAO,OAAO,aAAa,cAAc;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,3 +0,0 @@
1
- import { type DictionaryValue, type KeyPath } from '@intlayer/core';
2
- export declare const editDictionaryByKeyPath: (dictionaryContent: DictionaryValue, keyPath: KeyPath[], newValue: DictionaryValue) => DictionaryValue;
3
- //# sourceMappingURL=editDictionaryByKeyPath.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"editDictionaryByKeyPath.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,OAAO,EAAY,MAAM,gBAAgB,CAAC;AAI9E,eAAO,MAAM,uBAAuB,sBACf,eAAe,WACzB,OAAO,EAAE,YACR,eAAe,KACxB,eAgEF,CAAC"}
@@ -1,3 +0,0 @@
1
- import { type DictionaryValue, type KeyPath } from '@intlayer/core';
2
- export declare const getDictionaryValueByKeyPath: (dictionaryContent: DictionaryValue, keyPath: KeyPath[]) => DictionaryValue;
3
- //# sourceMappingURL=getDictionaryValueByKeyPath.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getDictionaryValueByKeyPath.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/getDictionaryValueByKeyPath.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,OAAO,EAAY,MAAM,gBAAgB,CAAC;AAE9E,eAAO,MAAM,2BAA2B,sBACnB,eAAe,WACzB,OAAO,EAAE,KACjB,eAcF,CAAC"}
@@ -1,3 +0,0 @@
1
- import { type DictionaryValue, NodeType } from '@intlayer/core';
2
- export declare const getSectionType: (section: DictionaryValue) => NodeType;
3
- //# sourceMappingURL=getSectionType.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getSectionType.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/getSectionType.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EACpB,QAAQ,EACT,MAAM,gBAAgB,CAAC;AAGxB,eAAO,MAAM,cAAc,YAAa,eAAe,KAAG,QA0BzD,CAAC"}
@@ -1,6 +0,0 @@
1
- export * from './editDictionaryByKeyPath';
2
- export * from './getDictionaryValueByKeyPath';
3
- export * from './getSectionType';
4
- export * from './removeDictionaryValueByKeyPath';
5
- export * from './renameDictionaryValueByKeyPath';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC"}
@@ -1,9 +0,0 @@
1
- /**
2
- * Verifies the object is a ReactElement.
3
- * See https://reactjs.org/docs/react-api.html#isvalidelement
4
- * @param object
5
- * @return True if `object` is a ReactElement.
6
- * @final
7
- */
8
- export declare const isValidElement: (object: any) => boolean;
9
- //# sourceMappingURL=isValidReactElement.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isValidReactElement.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/isValidReactElement.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AAEH,eAAO,MAAM,cAAc,WAAY,GAAG,KAAG,OAGL,CAAC"}
@@ -1,3 +0,0 @@
1
- import { DictionaryValue, KeyPath } from '@intlayer/core';
2
- export declare const removeDictionaryValueByKeyPath: (dictionaryContent: DictionaryValue, keyPath: KeyPath[]) => DictionaryValue;
3
- //# sourceMappingURL=removeDictionaryValueByKeyPath.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"removeDictionaryValueByKeyPath.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/removeDictionaryValueByKeyPath.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAY,MAAM,gBAAgB,CAAC;AAEpE,eAAO,MAAM,8BAA8B,sBACtB,eAAe,WACzB,OAAO,EAAE,KACjB,eA6BF,CAAC"}
@@ -1,3 +0,0 @@
1
- import { DictionaryValue, KeyPath } from '@intlayer/core';
2
- export declare const renameDictionaryValueByKeyPath: (dictionaryContent: DictionaryValue, newKey: string | number, keyPath: KeyPath[]) => DictionaryValue;
3
- //# sourceMappingURL=renameDictionaryValueByKeyPath.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renameDictionaryValueByKeyPath.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/renameDictionaryValueByKeyPath.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAY,MAAM,gBAAgB,CAAC;AAEpE,eAAO,MAAM,8BAA8B,sBACtB,eAAe,UAC1B,MAAM,GAAG,MAAM,WACd,OAAO,EAAE,KACjB,eAwCF,CAAC"}