UNPKG

react-native-notificare

Version:
51 lines (50 loc) 1.74 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.copyResources = copyResources; exports.replace = replace; exports.replaceAll = replaceAll; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); function copyResources(srcPath, destPath) { const exists = fs_1.default.existsSync(srcPath); if (!exists) { return; } const isDirectory = fs_1.default.statSync(srcPath).isDirectory(); if (exists && isDirectory) { fs_1.default.mkdirSync(destPath); fs_1.default.readdirSync(srcPath).forEach(function (fileName) { copyResources(path_1.default.join(srcPath, fileName), path_1.default.join(destPath, fileName)); }); } else { fs_1.default.copyFileSync(srcPath, destPath); } } /** * @throws {Error} */ function replace(contents, match, replace) { if (typeof match === 'string' && !contents.includes(match)) { throw new Error('Could not find content to replace.'); } if (match instanceof RegExp && !match.test(contents)) { throw new Error('Could not find content to replace.'); } return contents.replace(match, replace); } /** * @throws {Error} */ function replaceAll(contents, match, replace) { if (typeof match === 'string' && !contents.includes(match)) { throw new Error('Could not find content to replace.'); } if (match instanceof RegExp && !match.test(contents)) { throw new Error('Could not find content to replace.'); } return contents.replaceAll(match, replace); }