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