
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
essential-common-utils
Advanced tools
A collection of essesntial utility functions for various common operations in JavaScript and TypeScript projects. The essential-common-utils
package provides a set of reusable functions for string manipulation, number formatting, URL extraction, and more.
generateRandomArrayIndex
Generates a random index for an array.
arrayLength
(optional, default: 5
)const randomIndex = generateRandomArrayIndex(10);
trimAndRemoveSpaces
Trims a string and removes all spaces.
input
(string)const result = trimAndRemoveSpaces(' Hello World ');
// Output: "HelloWorld"
extractUrlsFromText
Extracts URLs from a given text.
text
(string)const urls = extractUrlsFromText('Check out https://example.com');
// Output: ["https://example.com"]
trimAndRemoveDoubleSpaces
Trims a string and removes double spaces.
input
(string)const result = trimAndRemoveDoubleSpaces('Hello World');
// Output: "Hello World"
trimAndRemoveUnicodeCharacter
Trims a string and removes a specific Unicode character.
input
(string)const result = trimAndRemoveUnicodeCharacter('HelloWorld');
// Output: "HelloWorld"
normalizeWhitespace
Normalizes whitespace in a string.
input
(string)const result = normalizeWhitespace("Hello
World");
// Output: "Hello World"
splitTextAndGetPart
Splits a text by a delimiter and returns a specific part.
text
(string): Text to split.delimiter
(string): Delimiter for splitting.index
(number): Index of the desired part.const part = splitTextAndGetPart('apple,orange,banana', ',', 1);
// Output: "orange"
normalizeWhitespacesAndRemoveSoftHyphen
Normalizes whitespace and removes soft hyphen characters.
text
(string)const result = normalizeWhitespacesAndRemoveSoftHyphen('Hello World');
// Output: "Hello World"
capitalizeFirstWord
Capitalizes the first word and makes the rest lowercase.
text
(string)const result = capitalizeFirstWord('hello world');
// Output: "Hello world"
convertToEuropeFormat
Converts a number to a European format string.
value
(number)const formatted = convertToEuropeFormat(123456.789);
// Output: "123.456,79"
getCamelCaseText
Converts a string to camelCase.
text
(string)const result = getCamelCaseText('Hello World');
// Output: "helloWorld"
getPascalCaseText
Converts a string to PascalCase.
text
(string)const result = getPascalCaseText('hello world');
// Output: "HelloWorld"
getExecutionTime
Calculates the execution time in seconds.
startTime
(number)const start = Date.now();
// some process
const time = getExecutionTime(start);
// Output: "0.12"
extractTextOnly
Extracts text content, removing numbers and currency symbols.
input
(string)const result = extractTextOnly('Price: $123.45');
// Output: "Price"
trimToTwoDecimalPlaces
Trims a number to two decimal places.
num
(number)const trimmed = trimToTwoDecimalPlaces(123.456);
// Output: 123.46
getMultipleUniqueIndexes
Generates multiple unique indexes for an array.
arrayLength
(number)count
(number)const indexes = getMultipleUniqueIndexes(10, 5);
// Output: [1, 3, 5, 7, 9]
getRandomString
Returns a random string from the provided list.
items
(string[]): An array of items to choose from.const randomQuote = getRandomString(['apple', 'banana', 'cherry']);
// Output: "banana" (or any other item from the array)
parsePricesWithLocaleFormatting
Parses a price string with locale formatting, handling different formats like European and default parsing.
priceText
(string)const price = parsePricesWithLocaleFormatting('$1,234.56');
// Output: 1234.56
textHelper
A collection of text helper functions for handling HTML entities and text normalization.
decodeHtmlEntities
Decodes HTML entities using a simple replacement approach.
text
(string) - The text that might contain HTML entitiesconst decoded = textHelper.decodeHtmlEntities('<div>Hello World</div>');
// Output: "<div>Hello World</div>"
normalizeText
Normalizes text by decoding HTML entities and standardizing special characters.
text
(string) - The text to normalizeconst normalized = textHelper.normalizeText('"Smart quotes" and 'apostrophes'');
// Output: '"Smart quotes" and \'apostrophes\''
compareTexts
Compares two strings after normalization.
actual
(string) - The actual text from the pageexpected
(string) - The expected text from test dataconst matches = textHelper.compareTexts('"Hello"', '"Hello"');
// Output: true
To use these utilities, import them from the Common.ts
file in your project. For example:
import {generateRandomArrayIndex, trimAndRemoveSpaces} from './src/Common';
const index = generateRandomArrayIndex(10);
const text = trimAndRemoveSpaces(' Hello World ');
Contributions are welcome! If you'd like to report a bug, suggest a feature, or contribute to the codebase, feel free to open an issue or submit a pull request.
This package is licensed under the MIT License.
FAQs
A collection of essential utilities for various tasks
The npm package essential-common-utils receives a total of 1,031 weekly downloads. As such, essential-common-utils popularity was classified as popular.
We found that essential-common-utils demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.