UNPKG

node-shntool

Version:

Node interface to shntool (http://www.etree.org/shnutils/shntool/)

44 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("console"); /*** SAFE STRING ***/ const UNICODE_CHARS = { '<': '\\u003C', '>': '\\u003E', '/': '\\u002F', '\u2028': '\\u2028', '\u2029': '\\u2029', }; const UNSAFE_CHARS_PATTERN = /[<>/\u2028\u2029]/g; function replaceUnsafeChar(char) { return UNICODE_CHARS[char]; } function atomSafeString(str) { if (str === '') return str; if (str === null || str === undefined) return undefined; if (typeof str !== 'string') { console.error('non-string passed to safeString()'); return undefined; } // this code adapted from rtsao/safe-string return str.replace(UNSAFE_CHARS_PATTERN, replaceUnsafeChar); } function safeString(str) { return atomSafeString(str); } exports.safeString = safeString; /*** SAFE BOOLEAN ***/ function atomSafeBoolean(bool) { if (typeof bool !== 'boolean') { console.error('non-boolean passed to safeBoolean()'); return undefined; } return (bool !== null && bool !== undefined && bool !== false && !!bool); } function safeBoolean(bool) { return atomSafeBoolean(bool); } exports.safeBoolean = safeBoolean; //# sourceMappingURL=utils.js.map