1"use strict"; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6exports.getProjectStringsXMLPathAsync = getProjectStringsXMLPathAsync; 7exports.removeStringItem = removeStringItem; 8exports.setStringItem = setStringItem; 9 10function _Paths() { 11 const data = require("./Paths"); 12 13 _Paths = function () { 14 return data; 15 }; 16 17 return data; 18} 19 20async function getProjectStringsXMLPathAsync(projectRoot, { 21 kind 22} = {}) { 23 return (0, _Paths().getResourceXMLPathAsync)(projectRoot, { 24 kind, 25 name: 'strings' 26 }); 27} 28 29function setStringItem(itemToAdd, stringFileContentsJSON) { 30 var _stringFileContentsJS; 31 32 if (!(stringFileContentsJSON !== null && stringFileContentsJSON !== void 0 && (_stringFileContentsJS = stringFileContentsJSON.resources) !== null && _stringFileContentsJS !== void 0 && _stringFileContentsJS.string)) { 33 if (!stringFileContentsJSON.resources || typeof stringFileContentsJSON.resources === 'string') { 34 // file was empty and JSON is `{resources : ''}` 35 stringFileContentsJSON.resources = {}; 36 } 37 38 stringFileContentsJSON.resources.string = itemToAdd; 39 return stringFileContentsJSON; 40 } 41 42 for (const newItem of itemToAdd) { 43 const stringNameExists = stringFileContentsJSON.resources.string.findIndex(e => e.$.name === newItem.$.name); 44 45 if (stringNameExists > -1) { 46 // replace the previous item 47 stringFileContentsJSON.resources.string[stringNameExists] = newItem; 48 } else { 49 stringFileContentsJSON.resources.string = stringFileContentsJSON.resources.string.concat(newItem); 50 } 51 } 52 53 return stringFileContentsJSON; 54} 55 56function removeStringItem(named, stringFileContentsJSON) { 57 var _stringFileContentsJS2; 58 59 if (stringFileContentsJSON !== null && stringFileContentsJSON !== void 0 && (_stringFileContentsJS2 = stringFileContentsJSON.resources) !== null && _stringFileContentsJS2 !== void 0 && _stringFileContentsJS2.string) { 60 const stringNameExists = stringFileContentsJSON.resources.string.findIndex(e => e.$.name === named); 61 62 if (stringNameExists > -1) { 63 // replace the previous value 64 stringFileContentsJSON.resources.string.splice(stringNameExists, 1); 65 } 66 } 67 68 return stringFileContentsJSON; 69} 70//# sourceMappingURL=Strings.js.map