UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

71 lines (67 loc) 1.23 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); /** * 移除第一个反斜杠 * * @export * @param {string} [str=''] 输入字符串 * @returns {string} 字符串 * @example * ```ts * removeFirstSlash('/abc/ddd/') * * 'abc/ddd/' * ``` */ function removeFirstSlash(str) { if (str === void 0) { str = ''; } if (str.startsWith('/')) { return str.slice(1); } return str; } /** * 移除最后一个反斜杠 * * @export * @param {string} [str=''] 输入字符串 * @returns {string} 字符串 * * @example * ```ts * removeLastSlash('/abc/') * * '/abc' * ``` */ function removeLastSlash(str) { if (str === void 0) { str = ''; } return str.replace(/\/$/, ''); } /** *移除第一个和最后一个反斜杠 * * @export * @param {string} [str=''] 输入字符串 * @returns {string} 字符串 * * @example * ```ts * removeFirstAndLastSlash('/abc/') * * 'abc' * ``` */ function removeFirstAndLastSlash(str) { if (str === void 0) { str = ''; } return str.replace(/^\/|\/$/g, ''); } exports.removeFirstAndLastSlash = removeFirstAndLastSlash; exports.removeFirstSlash = removeFirstSlash; exports.removeLastSlash = removeLastSlash;