Socket
Socket
Sign inDemoInstall

@akcybex/jstr

Package Overview
Dependencies
205
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @akcybex/jstr

`@akcybex/jstr` is a JavaScript library inspired by [Laravel 'Strings'](https://laravel.com/docs/10.x/strings) offering a chainable API for streamlined string manipulation and facilitating common string operations in javascript with enhanced expressivenes


Version published
Weekly downloads
9
decreased by-89.53%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

JSTR

@akcybex/jstr is a JavaScript library inspired by Laravel 'Strings' offering a chainable API for streamlined string manipulation and facilitating common string operations in javascript with enhanced expressiveness.

NPM Version NPM Downloads File Size

Installation

Using npm

You can install @akcybex/jstr using npm:

npm i @akcybex/jstr -S

Using Yarn

Alternatively, you can use Yarn to add the package:

yarn add @akcybex/jstr

Usage in Node.js

After installing, you can use @akcybex/jstr in your Node.js application:

import JStr from "@akcybex/jstr";

const result = JStr.of("hello").repeat(3).upper().toString();
console.log(result); // Outputs: 'HELLOHELLOHELLO'

Usage with CDN

For browser-based projects, you can use the CDN link:

<script src="https://unpkg.com/@akcybex/jstr@x.x.x/dist/jstr.umd.js"></script>

After including the script, jstr will be available globally:

<script>
  const result = JStr.of("hello").repeat(3).upper().toString();
  console.log(result); // Outputs: 'HELLOHELLOHELLO'
</script>

Available Methods

[!NOTE]
Methods with ✔✔ mark are included in the library and tested as well.

Strings

A string is a fundamental data type in programming used to represent a sequence of characters. It stores and manipulates text data, and string operations are typically performed using methods or functions provided by the programming language or relevant libraries. Common operations include concatenation, searching, replacing, and formatting strings.

JSTR String MethodsDescriptionDocumentation Link
✔✔ JStr.afterReturns the portion of the string that comes after a specified substring.Documentation
✔✔ JStr.afterLastReturns the portion of the string that comes after the last occurrence of a specified substring.Documentation
✔✔ JStr.asciiReturns the ASCII representation of the string.Documentation
✔✔ JStr.beforeReturns the portion of the string that comes before a specified substring.Documentation
✔✔ JStr.beforeLastReturns the portion of the string that comes before the last occurrence of a specified substring.Documentation
✔✔ JStr.betweenReturns the portion of the string that is between two specified substrings.Documentation
✔✔ JStr.betweenFirstReturns the portion of the string that is between the first occurrence of two specified substrings.Documentation
✔✔ JStr.camelConverts the string to camel case.Documentation
✔✔ JStr.charAtReturns the character at the specified position in the string.Documentation
✔✔ JStr.containsChecks if the string contains a specified substring.Documentation
✔✔ JStr.containsAllChecks if the string contains all of the specified substrings.Documentation
✔✔ JStr.endsWithChecks if the string ends with a specified suffix.Documentation
JStr.excerptReturns an excerpt from the string with a specified length.Documentation
✔✔ JStr.finishEnsures that the string ends with a specified suffix.Documentation
✔✔ JStr.headlineConverts the string to a headline format.Documentation
✔✔ JStr.capitalizeConverts the string to a capitalize format.Documentation
JStr.inlineMarkdownConverts the string to inline Markdown format.Documentation
✔✔ JStr.isChecks if the string is equal to a specified value.Documentation
✔✔ JStr.isAsciiChecks if the string contains only ASCII characters.Documentation
✔✔ JStr.isJsonChecks if the string is a valid JSON format.Documentation
JStr.isUlidChecks if the string is a valid ULID (Universally Unique Lexicographically Sortable Identifier).Documentation
✔✔ JStr.isUrlChecks if the string is a valid URL.Documentation
JStr.isUuidChecks if the string is a valid UUID (Universally Unique Identifier).Documentation
✔✔ JStr.kebabConverts the string to kebab case.Documentation
✔✔ JStr.lcfirstConverts the first character of the string to lowercase.Documentation
✔✔ JStr.lengthReturns the length of the string.Documentation
✔✔ JStr.limitLimits the length of the string to a specified number of characters.Documentation
✔✔ JStr.lowerConverts the string to lowercase.Documentation
✔✔ JStr.ltrimRemoves whitespace from the beginning of the string.Documentation
JStr.markdownConverts the string to Markdown format.Documentation
✔✔ JStr.maskMasks part of the string with a specified character.Documentation
✔✔ JStr.matchPerforms a regular expression match on the string.Documentation
✔✔ JStr.matchAllPerforms a global regular expression match on the string.Documentation
✔✔ JStr.isMatchChecks if the string matches a specified pattern.Documentation
JStr.orderedUuidGenerates an ordered UUID (Universally Unique Identifier).Documentation
✔✔ JStr.padBothPads the string on both sides with a specified character to a specified length.Documentation
✔✔ JStr.padLeftPads the string on the left side with a specified character to a specified length.Documentation
✔✔ JStr.padRightPads the string on the right side with a specified character to a specified length.Documentation
✔✔ JStr.passwordGenerates a password string.Documentation
JStr.pluralConverts the string to plural form.Documentation
JStr.pluralStudlyConverts the string to plural studly form.Documentation
✔✔ JStr.positionFinds the position of the first occurrence of a substring in the string.Documentation
✔✔ JStr.randomGenerates a random string.Documentation
✔✔ JStr.removeRemoves a specified substring from the string.Documentation
✔✔ JStr.repeatRepeats the string a specified number of times.Documentation
✔✔ JStr.replaceReplaces occurrences of a specified substring with another substring.Documentation
✔✔ JStr.replaceArrayReplaces occurrences of specified substrings with corresponding replacements.Documentation
✔✔ JStr.replaceFirstReplaces the first occurrence of a specified substring with another substring.Documentation
✔✔ JStr.replaceLastReplaces the last occurrence of a specified substring with another substring.Documentation
✔✔ JStr.rtrimRemoves whitespace from the end of the string.Documentation
✔✔ JStr.reverseReverses the characters of the string.Documentation
JStr.singularConverts the string to singular form.Documentation
JStr.slugConverts the string to a URL-friendly slug.Documentation
✔✔ JStr.snakeConverts the string to snake case.Documentation
JStr.squishReduces multiple consecutive whitespace characters to a single space.Documentation
✔✔ JStr.startAdds a specified prefix to the beginning of the string.Documentation
JStr.startsWithChecks if the string starts with a specified prefix.Documentation
✔✔ JStr.studlyConverts the string to studly case.Documentation
JStr.substrReturns a substring of the string starting from a specified position.Documentation
JStr.substrCountCounts the number of occurrences of a substring in the string.Documentation
JStr.substrReplaceReplaces a portion of the string with a specified substring.Documentation
JStr.swapSwaps the case of each character in the string.Documentation
JStr.takeReturns the first n characters from the string.Documentation
JStr.titleConverts the first character of each word in the string to uppercase.Documentation
✔✔ JStr.trimRemoves whitespace from the beginning and end of the string.Documentation
JStr.toHtmlStringConverts the string to its HTML-encoded representation.Documentation
✔✔ JStr.ucfirstConverts the first character of the string to uppercase.Documentation
JStr.ucsplitSplits the string into an array of words.Documentation
✔✔ JStr.upperConverts the string to uppercase.Documentation
JStr.ulidGenerates a ULID (Universally Unique Lexicographically Sortable Identifier).Documentation
✔✔ JStr.uuidGenerates a UUID (Universally Unique Identifier).Documentation
JStr.wordCountCounts the number of words in the string.Documentation
JStr.wordWrapWraps the string at a specified length with a specified line ending.Documentation
JStr.wordsSplits the string into an array of words.Documentation
JStr.wrapWraps the string at a specified length with a specified string.Documentation

Fluent String

Fluent strings provide a more fluent, object-oriented interface for working with string values. This paradigm allows you to chain multiple string operations together, creating a more readable syntax compared to traditional string operations. Each method call returns a new fluent string object, enabling you to seamlessly chain operations while maintaining clarity and conciseness in your code.

JSTR Fluent String MethodsDescriptionDocumentation Link
✔✔ afterReturns the portion of the string that comes after a specified substring.Documentation
✔✔ afterLastReturns the portion of the string that comes after the last occurrence of a specified substring.Documentation
appendAppends a string or an array of strings to the end of the current string.Documentation
✔✔ asciiReturns the ASCII representation of the string.Documentation
basenameReturns the trailing name component of a path.Documentation
✔✔ beforeReturns the portion of the string that comes before a specified substring.Documentation
✔✔ beforeLastReturns the portion of the string that comes before the last occurrence of a specified substring.Documentation
✔✔ betweenReturns the portion of the string that is between two specified substrings.Documentation
✔✔ betweenFirstReturns the portion of the string that is between the first occurrence of two specified substrings.Documentation
✔✔ camelConverts the string to camel case.Documentation
✔✔ charAtReturns the character at the specified position in the string.Documentation
classBasenameReturns the class basename of a fully qualified class name.Documentation
✔✔ containsChecks if the string contains a specified substring.Documentation
✔✔ containsAllChecks if the string contains all of the specified substrings.Documentation
dirnameReturns the directory name component of a path.Documentation
✔✔ endsWithChecks if the string ends with a specified suffix.Documentation
excerptReturns an excerpt from the string with a specified length.Documentation
exactlyChecks if the string is exactly equal to a specified value.Documentation
explodeSplits the string by a specified delimiter and returns an array of the parts.Documentation
✔✔ finishEnsures that the string ends with a specified suffix.Documentation
✔✔ headlineConverts the string to a headline format.Documentation
✔✔ capitalizeConverts the string to a capitalize format.Documentation
inlineMarkdownConverts the string to inline Markdown format.Documentation
✔✔ isChecks if the string is equal to a specified value.Documentation
✔✔ isAsciiChecks if the string contains only ASCII characters.Documentation
✔✔ isEmptyChecks if the string is empty.Documentation
isNotEmptyChecks if the string is not empty.Documentation
✔✔ isJsonChecks if the string is a valid JSON format.Documentation
isUlidChecks if the string is a valid ULID (Universally Unique Lexicographically Sortable Identifier).Documentation
✔✔ isUrlChecks if the string is a valid URL.Documentation
isUuidChecks if the string is a valid UUID (Universally Unique Identifier).Documentation
✔✔ kebabConverts the string to kebab case.Documentation
✔✔ lcfirstConverts the first character of the string to lowercase.Documentation
✔✔ lengthReturns the length of the string.Documentation
✔✔ limitLimits the length of the string to a specified number of characters.Documentation
✔✔ lowerConverts the string to lowercase.Documentation
✔✔ ltrimRemoves whitespace from the beginning of the string.Documentation
markdownConverts the string to Markdown format.Documentation
✔✔ maskMasks part of the string with a specified character.Documentation
✔✔ matchPerforms a regular expression match on the string.Documentation
✔✔ matchAllPerforms a global regular expression match on the string.Documentation
✔✔ isMatchChecks if the string matches a specified pattern.Documentation
newLineReplaces each occurrence of a newline character with a specified string.Documentation
✔✔ padBothPads the string on both sides with a specified character to a specified length.Documentation
✔✔ padLeftPads the string on the left side with a specified character to a specified length.Documentation
✔✔ padRightPads the string on the right side with a specified character to a specified length.Documentation
pipePasses the string to a callback and returns the result.Documentation
pluralConverts the string to plural form.Documentation
✔✔ positionFinds the position of the first occurrence of a substring in the string.Documentation
prependPrepends a string or an array of strings to the beginning of the current string.Documentation
✔✔ removeRemoves a specified substring from the string.Documentation
✔✔ repeatRepeats the string a specified number of times.Documentation
✔✔ replaceReplaces occurrences of a specified substring with another substring.Documentation
✔✔ replaceArrayReplaces occurrences of specified substrings with corresponding replacements.Documentation
✔✔ replaceFirstReplaces the first occurrence of a specified substring with another substring.Documentation
✔✔ replaceLastReplaces the last occurrence of a specified substring with another substring.Documentation
replaceMatchesReplaces occurrences of a specified pattern with a callback result.Documentation
✔✔ reverseReverses the characters of the string.Documentation
✔✔ rtrimRemoves whitespace from the end of the string.Documentation
scanReturns an array of all occurrences of a regular expression pattern in the string.Documentation
singularConverts the string to singular form.Documentation
slugConverts the string to a URL-friendly slug.Documentation
✔✔ snakeConverts the string to snake case.Documentation
splitSplits the string by a specified delimiter and returns an array of the parts.Documentation
squishReduces multiple consecutive whitespace characters to a single space.Documentation
✔✔ startAdds a specified prefix to the beginning of the string.Documentation
startsWithChecks if the string starts with a specified prefix.Documentation
✔✔ studlyConverts the string to studly case.Documentation
pluralStudyConverts the string to studly case.Documentation
substrReturns a substring of the string starting from a specified position.Documentation
substrCountCounts the number of occurrences of a substring in the string.Documentation
substrReplaceReplaces a portion of the string with a specified substring.Documentation
swapSwaps the case of each character in the string.Documentation
takeReturns the first n characters from the string.Documentation
tapPasses the string to a callback and returns the string.Documentation
testPerforms a regular expression match on the string and returns a boolean.Documentation
✔✔ titleConverts the first character of each word in the string to uppercase.Documentation
✔✔ trimRemoves whitespace from the beginning and end of the string.Documentation
✔✔ ucfirstConverts the first character of the string to uppercase.Documentation
ucsplitSplits the string into an array of words.Documentation
✔✔ upperConverts the string to uppercase.Documentation
whenExecutes a callback if a given condition is true.Documentation
whenContainsExecutes a callback if the string contains a specified substring.Documentation
whenContainsAllExecutes a callback if the string contains all of the specified substrings.Documentation
whenEmptyExecutes a callback if the string is empty.Documentation
whenNotEmptyExecutes a callback if the string is not empty.Documentation
whenStartsWithExecutes a callback if the string starts with a specified prefix.Documentation
whenEndsWithExecutes a callback if the string ends with a specified suffix.Documentation
whenExactlyExecutes a callback if the string is exactly equal to a specified value.Documentation
whenNotExactlyExecutes a callback if the string is notDocumentation
whenIsExecutes a callback if the string is equal to a specified value.Documentation
whenIsAsciiExecutes a callback if the string contains only ASCII characters.Documentation
whenIsUlidExecutes a callback if the string is a valid ULID.Documentation
whenIsUuidExecutes a callback if the string is a valid UUID.Documentation
whenTestExecutes a callback if a regular expression test on the string is true.Documentation
wordCountCounts the number of words in the string.Documentation
wordsSplits the string into an array of words.Documentation
wordWrapWraps the string at a specified length with a specified line ending.Documentation

Contributing

Contributions to @akcybex/jstr are welcome. Please refer to the contributing guidelines for more information.

License

This project is licensed under the MIT License.

Keywords

FAQs

Last updated on 30 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc