1.0.7 • Published 8 months ago

@navin0507/string-utilsmns v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

šŸ“œ String Utilities - @navin0507/string-utilsmns

A lightweight and powerful string utility package for JavaScript & TypeScript. It provides essential string manipulation functions for web development and general programming.

šŸš€ Features

āœ” Extract initials from a string
āœ” Convert strings to different cases (kebab-case, PascalCase, snake_case)
āœ” Generate random strings and slugs
āœ” Sanitize HTML & validate URLs
āœ” Encode/decode URLs & handle query strings
āœ” Format and transform text easily


šŸ“¦ Installation

Install via npm:

npm install @navin0507/string-utilsmns

or via yarn:

yarn add @navin0507/string-utilsmns

šŸš€ Usage

Import functions in your JavaScript or TypeScript project:

const { getInitials, toKebaCase, isValidEmail } = require('@navin0507/string-utilsmns');

// Extract initials
console.log(getInitials("John Doe", 2)); // Output: JD

// Convert to kebab-case
console.log(toKebaCase("Hello World")); // Output: hello-world

// Validate Email
console.log(isValidEmail("test@example.com")); // Output: true

šŸ“š Functions & Use Cases

FunctionDescriptionExample Usage
getInitials(str, length)Extracts initials from a namegetInitials("John Doe", 2) → "JD"
getRandomString(length)Generates a random alphanumeric stringgetRandomString(8) → "aB9xT3pL"
toKebaCase(str)Converts string to kebab-casetoKebaCase("Hello World") → "hello-world"
toSnakeCase(str)Converts string to snake_casetoSnakeCase("Hello World") → "hello_world"
toPascalCase(str)Converts string to PascalCasetoPascalCase("hello world") → "HelloWorld"
truncateString(str, length)Truncates string with ...truncateString("Hello World", 5) → "Hello..."
removeWhitespace(str)Removes all whitespace from stringremoveWhitespace("Hello World") → "HelloWorld"
toTitleCase(str)Converts to Title CasetoTitleCase("hello world") → "Hello World"
toSlug(str)Converts string to a slugtoSlug("Hello World!") → "hello-world"
maskString(str, visibleCount, maskChar)Masks a string (e.g., credit card, email)maskString("12345678", 4, "*") → "****5678"
handleURL(str, type)Encodes or decodes a URLhandleURL("Hello World!", "encode") → "Hello%20World%21"
sanitizeHTML(str)Escapes HTML to prevent XSS attackssanitizeHTML('<script>alert("XSS")</script>') → "&lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;"
getDomain(url)Extracts domain from a URLgetDomain("https://example.com/page") → "example.com"
isValidEmail(email)Validates email formatisValidEmail("test@example.com") → true
parseQueryString(query)Converts query string to an objectparseQueryString("name=John&age=25") → { name: "John", age: "25" }
toQueryString(params)Converts an object to a query stringtoQueryString({ name: "John", age: 25 }) → "name=John&age=25"
stripHTML(str)Removes all HTML tagsstripHTML("<p>Hello</p>") → "Hello"
isValidURL(str)Checks if a string is a valid URLisValidURL("https://google.com") → true
normalizeURL(url)Ensures URL has http:// or https://normalizeURL("google.com") → "https://google.com"
obfuscateEmail(email)Hides email partially for privacyobfuscateEmail("test@example.com") → "****@example.com"
getRandomHexColor()Generates a random hex colorgetRandomHexColor() → "#a3f4c9"
rgbToHex(r, g, b)Converts RGB to HEX colorrgbToHex(255, 0, 0) → "#ff0000"
hexToRgb(hex)Converts HEX to RGB colorhexToRgb("#ff0000") → "rgb(255, 0, 0)"
isJSON(str)Checks if a string is valid JSONisJSON('{"name":"John"}') → true
addOrdinalSuffix(num)Adds ordinal suffix to a numberaddOrdinalSuffix(21) → "21st"
markdownToHTML(markdown)Converts basic markdown to HTMLmarkdownToHTML("**Bold**") → "<b>Bold</b>"

šŸ› ļø Contributing

Want to contribute? Awesome! šŸŽ‰
Follow these steps:
1. Fork the repository
2. Clone your fork:

git clone https://github.com/NAVIN0507/getStringUtils.git
  1. Create a branch:
    git checkout -b feature-new-function
  2. Make your changes & commit:
    git commit -m "Added new string utility function"
  3. Push & Create a PR:
    git push origin feature-new-function
    Open a Pull Request (PR) on GitHub šŸš€

šŸ“œ License

This package is licensed under the ISC License.
You are free to use, modify, and distribute it with attribution.

ISC License

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

šŸ“¢ Enjoy coding! If you like this package, don't forget to ⭐ it on GitHub! šŸš€

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago