UNPKG

fume-fhir-converter

Version:

FHIR-Utilized Mapping Engine - Community

104 lines 3.6 kB
"use strict"; /** * © Copyright Outburn Ltd. 2022-2024 All Rights Reserved * Project name: FUME-COMMUNITY */ Object.defineProperty(exports, "__esModule", { value: true }); exports.isNumeric = exports.matches = exports.uuid = exports.hashKey = exports.splitToLines = exports.removeEmptyLines = exports.substringAfter = exports.substringBefore = exports.initCapOnce = exports.endsWith = exports.startsWith = void 0; const tslib_1 = require("tslib"); // import jsonata from 'jsonata'; const crypto_1 = require("crypto"); const js_sha256_1 = require("js-sha256"); const uuid_by_string_1 = tslib_1.__importDefault(require("uuid-by-string")); const startsWith = (str, startStr) => { // undefined inputs always return undefined if (typeof str === 'undefined') return undefined; return str.startsWith(startStr); }; exports.startsWith = startsWith; const endsWith = (str, endStr) => { // undefined inputs always return undefined if (typeof str === 'undefined') return undefined; return str.endsWith(endStr); }; exports.endsWith = endsWith; const initCapOnce = (str) => { // used for polymorhic element names, where all type names need to // be appended to base element names but the result must be camelCased // e.g. if chosen type for value[x] is string, the element name will be valueString return str[0].toUpperCase() + str.slice(1); }; exports.initCapOnce = initCapOnce; const substringBefore = (str, chars) => { // undefined inputs always return undefined if (typeof str === 'undefined') { return ''; } ; const pos = str.indexOf(chars); if (pos > -1) { return str.substring(0, pos); } else { return str; } }; exports.substringBefore = substringBefore; const substringAfter = (str, chars) => { // undefined inputs always return undefined if (typeof str === 'undefined') { return ''; } const pos = str.indexOf(chars); if (pos > -1) { return str.substring(pos + chars.length); } else { return str; } }; exports.substringAfter = substringAfter; const removeEmptyLines = (arr) => { // removes empty lines from a line array let lines = []; if (typeof arr === 'string') { lines.push(arr); } else { lines = arr; } return lines.filter((line) => line.trim() !== ''); }; exports.removeEmptyLines = removeEmptyLines; // clean and split an expression. returns a line array const splitToLines = (expr) => (0, exports.removeEmptyLines)(expr.split(/\r?\n/)); exports.splitToLines = splitToLines; const hashKey = (str) => (0, js_sha256_1.sha256)(str + (0, exports.uuid)(str)); exports.hashKey = hashKey; const uuid = (seed) => seed ? (0, uuid_by_string_1.default)(seed) : (0, crypto_1.randomUUID)(); exports.uuid = uuid; const matches = (str, regex) => { /* match whole string (like fhirpath) */ const fn = new RegExp(`^${regex}$`); return fn.test(str); }; exports.matches = matches; const isNumeric = (n) => { if (typeof n === 'number') return true; if (typeof n === 'undefined') return undefined; // RegEx taken form the FHIR spec for the decimal datatype: https://www.hl7.org/fhir/r4/datatypes.html const isStrNumeric = (str) => /^-?(0|[1-9][0-9]*)(.[0-9]+)?([eE][+-]?[0-9]+)?$/.test(str); if (typeof n === 'string') return isStrNumeric(n); if (Array.isArray(n) && n.length === 1) { return (0, exports.isNumeric)(n[0]); } ; return false; }; exports.isNumeric = isNumeric; //# sourceMappingURL=stringFunctions.js.map