Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@limitless.claver/stringify
Advanced tools
String helper method for all string and JSON manipulations
Stringify provides a set of methods for working with JSON strings and objects, case conversion, as well as encryption and decryption capabilities. It extends the Ncrypt class for encryption and decryption, and also allows you to convert JSON strings to JSON objects, and vice versa.
In this library, you'll find a variety of string conversion methods such as converting strings to camel case, snake case, kebab case, and sentence case. You can also encrypt and decrypt strings using the encryption key provided or via the .env file.
This documentation provides an overview of the Stringify class, including its methods, parameters, return types, and examples of how to use them. Whether you're working on a small or large project, Stringify aims to provide an easy-to-use set of tools that can help you with common string manipulation tasks. q
To use Stringify, you need to have Node.js installed on your computer. Once you have Node.js installed, you can install the package using the following command in your terminal:
npm install @limitless.claver/stringify
.env
fileAdd a 32 character
length encryption key to the created .env
file. You can ignore this step if you do not intend to use the encryption methods of this library.
//.env
ENCRYPTION_KEY=6bef904c684547d18f15a47e09ecdbb3
toEncryptedString(value: any): string
Encrypts a string using the encryption key.
const plaintext = 'my secret message';
const encrypted = Stringify.toEncryptedString(plaintext);
console.log(encrypted); // Encrypted string
value
: The string to encrypt.toDecryptedString(value: string): string
Decrypts an encrypted string to plain text using the encryption key.
const encrypted = 'Encrypted string';
const plaintext = Stringify.toDecryptedString(encrypted);
console.log(plaintext); // 'my secret message'
value
: The encrypted string.toDecryptedJSON(value: string): any
Decrypts an encrypted string to a JSON object using the encryption key.
const encrypted = 'Encrypted JSON string';
const jsonObject = Stringify.toDecryptedJSON(encrypted);
console.log(jsonObject); // Decrypted JSON object
value
: The encrypted JSON string.formatString(template: string, values: Record<string, any>): string
The formatString
method replaces placeholders in a string template with values from an object.
template
(required) - The string template with placeholders to replace.values
(required) - The object containing the values to use for replacement.const template = 'Hello, ${firstName} ${lastName}!';
const values = { firstName: 'John', lastName: 'Doe' };
const formattedString = Stringify.formatString(template, values);
console.log(formattedString);
// Output: "Hello, John Doe!"
padLeft(str: string, length: number, paddingChar: string = " "): string
The padLeft
method pads a string on the left with a specified character until it reaches the desired length.
str
(required) - The string to pad.length
(required) - The length to which the string should be padded.paddingChar
(optional) - The character to use for padding. The default value is a space character.const str = '123';
const paddedString = Stringify.padLeft(str, 5, '0');
console.log(paddedString);
// Output: "00123"
padRight(str: string, length: number, paddingChar: string = " "): string
The padRight
method pads a string on the right with a specified character until it reaches the desired length.
str
(required) - The string to pad.length
(required) - The length to which the string should be padded.paddingChar
(optional) - The character to use for padding. The default value is a space character.const str = '123';
const paddedString = Stringify.padRight(str, 5, '0');
console.log(paddedString);
// Output: "12300"
truncate(str: string, maxLength: number, suffix: string = "..."): string
The truncate
method truncates a string to a specified maximum length and appends a suffix to the end of the string.
str
(required) - The string to truncate.maxLength
(required) - The maximum length of the truncated string.suffix
(optional) - The suffix to append to the end of the string if it is truncated. The default value is "...".const str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut perspiciatis unde omnis iste natus error sit voluptatem';
const truncatedString = Stringify.truncate(str, 50);
console.log(truncatedString);
// Output: "Lorem ipsum dolor sit amet, consectetur adipisc..."
const str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut perspiciatis unde omnis iste natus error sit voluptatem';
const truncatedString = Stringify.truncate(str, 50, "(continue)");
console.log(truncatedString);
// Output: "Lorem ipsum dolor sit amet, consectetur adipisc (continue)"
toTitleCase(str: string): string
Converts the first letter of each word in a given string to uppercase and the remaining letters to lowercase.
Stringify.toTitleCase("example sentence"); // "Example Sentence"
str
: The string to convert to title case.toUpperCase(str: string): string
Converts all letters in a given string to uppercase.
Stringify.toUpperCase("example sentence"); // "EXAMPLE SENTENCE"
str
: The string to convert to uppercase.toLowerCase(str: string): string
Converts all letters in a given string to lowercase.
Stringify.toLowerCase("Example Sentence"); // "example sentence"
str
: The string to convert to lowercase.replace(str: string, oldSubstring: string, newSubstring: string): string
Replaces all occurrences of a substring with a new substring in a given string.
str
: The input string to be processed.oldSubstring
: The substring to be replaced.newSubstring
: The new substring to replace the old substring.A new string with all occurrences of the old substring replaced with the new substring.
const input = "hello world";
const output = Stringify.replace(input, "world", "universe");
console.log(output); // "hello universe"
replaceAll(str: string, oldSubstring: string, newSubstring: string): string
Replaces all occurrences of a substring with a new substring in a given string.
str
: The input string to be processed.oldSubstring
: The substring to be replaced.newSubstring
: The new substring to replace the old substring.A new string with all occurrences of the old substring replaced with the new substring.
const input = "hello world";
const output = Stringify.replaceAll(input, "o", "x");
console.log(output); // "hellx wxrld"
removeWhitespace(value: string): string
Removes leading/trailing spaces and replaces multiple consecutive spaces with a single space.
value
: The string to remove whitespace from.A new string with whitespace removed.
const input = " hello world ";
const output = Stringify.removeWhitespace(input);
console.log(output); // "hello world"
reverse(value: string): string
Reverses the characters of a string.
value
: The input string to reverse.A new string with the characters reversed.
const input = "hello world";
const output = Stringify.reverse(input);
console.log(output); // "dlrow olleh"
reverseWords(str: string): string
Reverses the order of words in a string.
str
: The input string to be processed.A new string with the order of words reversed.
const input = "hello world";
const output = Stringify.reverseWords(input);
console.log(output); // "world hello"
shuffle(str: string): string
Shuffles the characters of a string.
str
: The input string to be shuffled.A new string with the characters of the input string shuffled.
const input = "hello world";
const output = Stringify.shuffle(input);
console.log(output); // Output will be different every time due to randomness
contains(str: string, substring: string): boolean
Returns a boolean indicating whether the string contains a specified substring.
str
: The input string to search in.substring
: The substring to search for.A boolean indicating whether the string contains the substring. true
if the substring is found, false
otherwise.
const input = "Hello, world!";
const hasComma = Stringify.contains(input, ",");
console.log(hasComma); // true
const hasExclamation = Stringify.contains(input, "!");
console.log(hasExclamation); // true
const hasNumbers = Stringify.contains(input, "123");
console.log(hasNumbers); // false
countOccurrences(str: string, substring: string): number
Returns the number of times a specified substring appears in the string.
str
: The input string to be searched.substring
: The substring to count occurrences of.The number of times the substring appears in the string.
const input = "hello world";
const count = Stringify.countOccurrences(input, "l");
console.log(count); // 3
slugify(str: string): string
The slugify()
function takes a string as input and returns a URL-friendly slug.
str
: A string to convert to a slug.The slugified string.
const str = "This is a string with spaces and special characters!";
const slug = slugify(str);
console.log(slug); // Output: "this-is-a-string-with-spaces-and-special-characters"
encodeQueryString(params: Record<string, any>): string
Encodes an object of key-value pairs as a URL query string.
Stringify.encodeQueryString({ foo: 'bar', baz: 'qux' }); // "foo=bar&baz=qux"
params
: An object containing key-value pairs to be encoded.decodeQueryString(queryString: string): Record<string, any>
Decodes a URL query string into an object of key-value pairs.
Stringify.decodeQueryString("foo=bar&baz=qux"); // { foo: 'bar', baz: 'qux' }
queryString
: A string containing the encoded key-value pairs as a query string.parseUrl(url: string): Record<string, any>
Parses a URL into an object containing its protocol, hostname, port, and pathname, as well as any query parameters.
Stringify.parseUrl("https://www.example.com/search?q=example");
// { protocol: 'https:', hostname: 'www.example.com', port: '', pathname: '/search', q: 'example' }
url
: The URL to be parsed.xmlToJson(xml: string): string
Converts XML string to valid JSON objects
Stringify.xmlToJson("<root><name>Claver</name></root>"); // "{name: 'Claver'}"
xml
: The XML string to convert to JSONjsonToXml(json: string): string
Converts JSON objects to valid XML
Stringify.jsonToXml({"name": "Claver"}); // <name>Claver</name>
xml
: The JSON object to convert to XMLtoJson
: Converts a JSON string to a JSON ObjecttoString
: Converts a JSON object to a string using JSON.stringify
Before you can use these methods, please add a .env
file with a 32 alpha numeric string
as an ENCRYPTION_KEY
.
toEncryptedString
: Encrypts and returns an encrypted hash of any string passed to it.toDecryptedString
: Decrypts the encrypted string and returns the original text.toDecryptedJSON
: Decrypts an encrypted stringified JSON object and returns the original JSON object.toCamelCase
: Converts a string to camel case.toSnakeCase
: Converts a string to snake case.toKebabCase
: Converts a string to kebab case.toSentenceCase
: Converts a string to sentence case.toTitleCase
: Converts a string to title case.toUpperCase
: Converts a string to uppercase.toLowerCase
: Converts a string to lowercase.encodeQueryString
: Encodes a query string.decodeQueryString
: Decodes a query string.parseUrl
: Parses a URL.formatString
: Formats a string with placeholders and values.padLeft
: Pads a string with characters on the left.padRight
: Pads a string with characters on the right.truncate
: Truncates a string to a specified length.FAQs
String helper method for all string and JSON manipulations
We found that @limitless.claver/stringify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.