This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.
2021-04-02 02:24:13 +03:00

42 lines
2.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Paths_1 = require("./Paths");
async function getProjectStringsXMLPathAsync(projectRoot, { kind } = {}) {
return Paths_1.getResourceXMLPathAsync(projectRoot, { kind, name: 'strings' });
}
exports.getProjectStringsXMLPathAsync = getProjectStringsXMLPathAsync;
function setStringItem(itemToAdd, stringFileContentsJSON) {
var _a;
if ((_a = stringFileContentsJSON === null || stringFileContentsJSON === void 0 ? void 0 : stringFileContentsJSON.resources) === null || _a === void 0 ? void 0 : _a.string) {
const stringNameExists = stringFileContentsJSON.resources.string.filter((e) => e.$.name === itemToAdd[0].$.name)[0];
if (stringNameExists) {
// replace the previous value
stringNameExists._ = itemToAdd[0]._;
}
else {
stringFileContentsJSON.resources.string = stringFileContentsJSON.resources.string.concat(itemToAdd);
}
}
else {
if (!stringFileContentsJSON.resources || typeof stringFileContentsJSON.resources === 'string') {
// file was empty and JSON is `{resources : ''}`
stringFileContentsJSON.resources = {};
}
stringFileContentsJSON.resources.string = itemToAdd;
}
return stringFileContentsJSON;
}
exports.setStringItem = setStringItem;
function removeStringItem(named, stringFileContentsJSON) {
var _a;
if ((_a = stringFileContentsJSON === null || stringFileContentsJSON === void 0 ? void 0 : stringFileContentsJSON.resources) === null || _a === void 0 ? void 0 : _a.string) {
const stringNameExists = stringFileContentsJSON.resources.string.findIndex((e) => e.$.name === named);
if (stringNameExists > -1) {
// replace the previous value
stringFileContentsJSON.resources.string.splice(stringNameExists, 1);
}
}
return stringFileContentsJSON;
}
exports.removeStringItem = removeStringItem;
//# sourceMappingURL=Strings.js.map