@vtrbo/utils-str
Advanced tools
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/str.ts | ||
| function toSlash(str) { | ||
| return str.replace(/\\/g, "/"); | ||
| } | ||
| function toLinesCase(str, isUnder = false) { | ||
| return str.replace(/^[-|_]+|[-|_]+$/g, "").replace(/^[A-Z]/g, (key) => key.toLowerCase()).replace(/[A-Z]/g, (key) => `${isUnder ? "_" : "-"}${key.toLowerCase()}`); | ||
| } | ||
| function toEscape(str) { | ||
| const escapeMap = { | ||
| "&": "&", | ||
| "<": "<", | ||
| ">": ">", | ||
| '"': """, | ||
| "'": "'" | ||
| }; | ||
| const regex = /(&|<|>|"|')/g; | ||
| return str.replace(regex, (match) => escapeMap[match]); | ||
| } | ||
| function capitalize(str) { | ||
| return str.charAt(0).toUpperCase() + str.slice(1); | ||
| } | ||
| function toCamelCase(str, isUpper = false) { | ||
| const camelCase = str.replace(/^[-|_]+|[-|_]+$/g, "").replace(/[-|_]+([a-z])/g, (_, key) => key.toUpperCase()).replace(/[-|_]+/g, ""); | ||
| return isUpper ? capitalize(camelCase) : camelCase; | ||
| } | ||
| function template(str, ...args) { | ||
| return str.replace(/{(\d+)}/g, (match, key) => { | ||
| const index = Number(key); | ||
| if (Number.isNaN(index)) | ||
| return match; | ||
| return args[index]; | ||
| }); | ||
| } | ||
| function ensureSuffix(str, suffix) { | ||
| if (!str.endsWith(suffix)) | ||
| return str + suffix; | ||
| return str; | ||
| } | ||
| function ensurePrefix(str, prefix) { | ||
| if (!str.startsWith(prefix)) | ||
| return prefix + str; | ||
| return str; | ||
| } | ||
| exports.capitalize = capitalize; exports.ensurePrefix = ensurePrefix; exports.ensureSuffix = ensureSuffix; exports.template = template; exports.toCamelCase = toCamelCase; exports.toEscape = toEscape; exports.toLinesCase = toLinesCase; exports.toSlash = toSlash; |
| declare function toSlash(str: string): string; | ||
| declare function toLinesCase(str: string, isUnder?: boolean): string; | ||
| declare function toEscape(str: string): string; | ||
| declare function capitalize(str: string): string; | ||
| declare function toCamelCase(str: string, isUpper?: boolean): string; | ||
| declare function template(str: string, ...args: any[]): string; | ||
| declare function ensureSuffix(str: string, suffix: string): string; | ||
| declare function ensurePrefix(str: string, prefix: string): string; | ||
| export { capitalize, ensurePrefix, ensureSuffix, template, toCamelCase, toEscape, toLinesCase, toSlash }; |
| declare function toSlash(str: string): string; | ||
| declare function toLinesCase(str: string, isUnder?: boolean): string; | ||
| declare function toEscape(str: string): string; | ||
| declare function capitalize(str: string): string; | ||
| declare function toCamelCase(str: string, isUpper?: boolean): string; | ||
| declare function template(str: string, ...args: any[]): string; | ||
| declare function ensureSuffix(str: string, suffix: string): string; | ||
| declare function ensurePrefix(str: string, prefix: string): string; | ||
| export { capitalize, ensurePrefix, ensureSuffix, template, toCamelCase, toEscape, toLinesCase, toSlash }; |
| // src/str.ts | ||
| function toSlash(str) { | ||
| return str.replace(/\\/g, "/"); | ||
| } | ||
| function toLinesCase(str, isUnder = false) { | ||
| return str.replace(/^[-|_]+|[-|_]+$/g, "").replace(/^[A-Z]/g, (key) => key.toLowerCase()).replace(/[A-Z]/g, (key) => `${isUnder ? "_" : "-"}${key.toLowerCase()}`); | ||
| } | ||
| function toEscape(str) { | ||
| const escapeMap = { | ||
| "&": "&", | ||
| "<": "<", | ||
| ">": ">", | ||
| '"': """, | ||
| "'": "'" | ||
| }; | ||
| const regex = /(&|<|>|"|')/g; | ||
| return str.replace(regex, (match) => escapeMap[match]); | ||
| } | ||
| function capitalize(str) { | ||
| return str.charAt(0).toUpperCase() + str.slice(1); | ||
| } | ||
| function toCamelCase(str, isUpper = false) { | ||
| const camelCase = str.replace(/^[-|_]+|[-|_]+$/g, "").replace(/[-|_]+([a-z])/g, (_, key) => key.toUpperCase()).replace(/[-|_]+/g, ""); | ||
| return isUpper ? capitalize(camelCase) : camelCase; | ||
| } | ||
| function template(str, ...args) { | ||
| return str.replace(/{(\d+)}/g, (match, key) => { | ||
| const index = Number(key); | ||
| if (Number.isNaN(index)) | ||
| return match; | ||
| return args[index]; | ||
| }); | ||
| } | ||
| function ensureSuffix(str, suffix) { | ||
| if (!str.endsWith(suffix)) | ||
| return str + suffix; | ||
| return str; | ||
| } | ||
| function ensurePrefix(str, prefix) { | ||
| if (!str.startsWith(prefix)) | ||
| return prefix + str; | ||
| return str; | ||
| } | ||
| export { | ||
| capitalize, | ||
| ensurePrefix, | ||
| ensureSuffix, | ||
| template, | ||
| toCamelCase, | ||
| toEscape, | ||
| toLinesCase, | ||
| toSlash | ||
| }; |
+10
-15
| { | ||
| "name": "@vtrbo/utils-str", | ||
| "type": "module", | ||
| "version": "0.4.0-beta.5", | ||
| "version": "0.4.0-beta.7", | ||
| "description": "Collection of common JavaScript or TypeScript utils.", | ||
@@ -24,15 +24,14 @@ "author": { | ||
| ".": { | ||
| "types": "./index.d.ts", | ||
| "import": "./index.js", | ||
| "require": "./index.cjs" | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.js", | ||
| "require": "./dist/index.cjs" | ||
| } | ||
| }, | ||
| "main": "./index.js", | ||
| "module": "./index.js", | ||
| "types": "./index.d.ts", | ||
| "main": "./dist/index.cjs", | ||
| "module": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "typesVersions": { | ||
| "*": { | ||
| "*": [ | ||
| "./*", | ||
| "./index.d.ts" | ||
| "./dist/index.d.ts" | ||
| ] | ||
@@ -42,10 +41,6 @@ } | ||
| "files": [ | ||
| "README.md", | ||
| "index.cjs", | ||
| "index.d.cts", | ||
| "index.d.ts", | ||
| "index.js" | ||
| "dist" | ||
| ], | ||
| "dependencies": { | ||
| "@vtrbo/utils-tool": "0.4.0-beta.5" | ||
| "@vtrbo/utils-tool": "0.4.0-beta.7" | ||
| }, | ||
@@ -52,0 +47,0 @@ "scripts": { |
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
6267
189.47%6
200%106
Infinity%0
-100%+ Added
- Removed