UNPKG

@airgap/coinlib-core

Version:

The @airgap/coinlib-core is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.

50 lines 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.capitalize = exports.trimStart = exports.extractGroups = void 0; function extractGroups(str, options) { var start; var depth = 0; var groups = []; for (var pos = 0; pos < str.length; pos++) { if (options.groupSeparator && str.charAt(pos) === options.groupSeparator) { continue; } if (options.groupStart.includes(str.charAt(pos))) { if (depth++ === 0) { start = pos + 1; } } else if (options.groupEnd.includes(str.charAt(pos))) { if (--depth === 0) { groups.push(str.slice(start, pos)); start = undefined; } } else if (options.groupSeparator && str.charAt(pos - 1) === options.groupSeparator) { if (depth === 0) { start = pos; } } else if (options.groupSeparator && str.charAt(pos + 1) === options.groupSeparator) { if (depth === 0) { groups.push(str.slice(start, pos + 1)); start = undefined; } } } if (start !== undefined) { groups.push(str.slice(start)); } return groups; } exports.extractGroups = extractGroups; function trimStart(value, char) { var regex = new RegExp("^".concat(char, "+"), 'g'); return value.replace(regex, ''); } exports.trimStart = trimStart; function capitalize(value) { return value.slice(0, 1).toUpperCase() + value.slice(1).toLowerCase(); } exports.capitalize = capitalize; //# sourceMappingURL=string.js.map