Library with some utility functions
npm install coreutilstsCoreUtilsTS is a TypeScript utility library offering a comprehensive suite of helper functions to simplify common development tasks. Built with clarity and reusability in mind, it works seamlessly in both browser and non-browser environments.
Note: Verify functionality for your specific use case before deploying in production.
Some functions act as wrappers around standard TypeScript operations to improve code readability and consistency.
Whether you need to perform object validations, string case transformations, encoding/decoding, hashing, or line-based manipulations, CoreUtilsTS is designed to streamline your workflow.
---
- Key Features
- Installation
- Usage
- Object Utilities
- Case Utilities
- Encoding & Cryptography
- Line Utilities
- String Utilities
- Object & Type Guards
- Case Utilities API
- Encoding & Cryptography API
- Line Utilities API
- String Utilities API
- Enumerations & Constants
- Logging
- Testing
- Local Build
- Dependencies
- License
---
- Object Utilities
- isNull(), isUndefined(), isNullOrUndefined()
- getDefaultOnNull() for fallback values
- isEmptyArray() checks for empty or missing arrays
- Case Utilities
- Determine string case: determineCase()
- Transform between cases: toLowerCase(), toUpperCase(), toSentenceCase(), toTitleCase(), toCamelCase(), toPascalCase(), toSnakeCase(), toKebabCase(), and more
- Swap, capitalize, and uncapitalize functions
- Encoding & Cryptography
- Base64 encoding/decoding: encodeBase64(), decodeBase64()
- URL-safe Base64: encodeBase64Url()
- Hashing algorithms: encodeSHA1(), encodeSHA256(), encodeSHA384(), encodeSHA512(), encodeMD5()
- Line Utilities
- Split strings into lines and remove empty entries: splitLines(), splitStringIntoLines()
- Sort (sortLines()), shuffle (shuffleLines()), and deduplicate (removeDuplicates()) arrays of lines
- String Utilities
- Type and content checks: isString(), isEmptyString(), isBlankString(), isNullOrBlankString(), isAlphanumeric(), isNotAlphanumeric()
- Search: startsWith(), endsWith(), contains()
- Join and split: joinStrings(), splitString()
- Conditional modifications: addSuffixIfMissing(), addPrefixIfMissing(), removePrefixIfPresent(), removeSuffixIfPresent()
- Replacements and safe extraction: replaceSubstring(), safeExtractText()
- URL utilities: slugifyString(), encodeUrl(), decodeUrl()
- Logging
- Configurable logger via setLogger()
- Built-in ConsoleLogger and SilentLogger
---
Install CoreUtilsTS via npm or yarn:
``bash`
npm install coreutilsts
or
`bash`
yarn add coreutilsts
---
Import only the modules you need to keep your bundle lean.
`typescript
import { ObjectUtils } from 'coreutilsts';
const value = null;
const safe = ObjectUtils.getDefaultOnNull(value, 'fallback');
`
`typescript
import { CaseUtils } from 'coreutilsts';
const text = 'example_string';
const title = CaseUtils.toTitleCase(text);
`
`typescript
import { EncodingUtils, HashingUtils } from 'coreutilsts';
const b64 = EncodingUtils.encodeBase64('hello');
HashingUtils.encodeSHA256('password').then((hash) => console.log(hash));
`
`typescript
import { LineUtils } from 'coreutilsts';
const lines = LineUtils.splitLines('first\n\nsecond');
const unique = LineUtils.removeDuplicates(lines);
`
`typescript
import { StringUtils } from 'coreutilsts';
const slug = StringUtils.slugifyString('My Blog Post Title');
const url = StringUtils.encodeUrl('https://example.com/?q=a b');
`
---
- isNull(value: unknown): value is null
- isUndefined(value: unknown): value is undefined
- isNullOrUndefined(value: unknown): value is null | undefined
- getDefaultOnNull(value: unknown, defaultValue: unknown): unknown
- isEmptyArray(value: undefined | null | unknown[]): boolean
- determineCase(input: string, props?: DetermineStringCaseProps): StringCaseTypes
- toLowerCase(input: string): string, toUpperCase(input: string): string
- toLowerCaseStrict(input: string): string, toUpperCaseStrict(input: string): string
- toSentenceCase(input: string): string, toTitleCase(input: string): string
- toCamelCase(input: string): string, toPascalCase(input: string): string
- toSnakeCase(input: string): string, toKebabCase(input: string): string
- Other cases: toScreamingSnakeCase(), toCobolCase(), toTrainCase(), toDotCase(), toSlashCase()
- swapCase(input: string): string, capitalize(input: string): string, uncapitalize(input: string): string
- encodeBase64(input: string): string
- encodeBase64Url(input: string): string
- decodeBase64(input: string): string
- encodeSHA1(input: string): Promise
- encodeSHA256(input: string): Promise
- encodeSHA384(input: string): Promise
- encodeSHA512(input: string): Promise
- encodeMD5(input: string): Promise
- splitStringIntoLines(data: string, splitter: string | RegExp): string[]
- splitLines(data: string | null | undefined): string[]
- sortLines(arr: string[], sortType?: SortingTypes): string[]
- shuffleLines(arr: string[]): string[]
- removeDuplicates(strings: string[], ignoreCase?: boolean): string[]
- Type Checks: isString(), isEmptyString(), isBlankString(), isNullOrBlankString(), isAlphanumeric(), isNotAlphanumeric()startsWith(inputString: string, value: string)
- Search: , endsWith(), contains()splitString(value: string, separator?: LineSeparator)
- Split & Join: , joinStrings(strings: string[], joinSymbol?: LineSeparator)addSuffixIfMissing()
- Conditional Mods: , addPrefixIfMissing(), removePrefixIfPresent(), removeSuffixIfPresent()replaceSubstring()
- Transform & Replace: , safeExtractText()slugifyString(value: string, separator?: string, lower?: boolean, locale?: string)
- URL Utilities: , encodeUrl(value: string), decodeUrl(value: string)
- Enums: EncoderAlg, Encodings, LineSeparators, SortingTypesEMPTY
- Constants: , SPACE
- setLogger(logger: LibLogger): void
- Built-in: ConsoleLogger, SilentLogger
---
Run the comprehensive test suite:
`bash`
npm run test
---
Build and verify locally:
`bash`
npm install
`bash`
npm run verify
---
This library depends on:
- crcjs-base64
- js-md5
- slugify`
-
---
This project is licensed under the MIT License.
---
Enjoy using CoreUtilsTS to streamline your development process with powerful, focused utilities!