UNPKG

@oxog/string

Version:

Comprehensive string manipulation utilities with zero dependencies

238 lines (237 loc) 7.66 kB
// Core exports export * from './core/case'; export * from './core/cleaning'; export * from './core/validation'; export * from './core/analysis'; export * from './core/manipulation'; export * from './core/encoding'; export * from './core/advanced'; // Type exports export * from './types'; // Plugin exports export * from './plugins/plugin-interface'; // Utility exports export * from './utils/unicode'; export * from './utils/algorithms'; // Re-export removeAccents explicitly to resolve ambiguity export { removeAccents } from './utils/unicode'; // Import all functions for APIs import * as Case from './core/case'; import * as Cleaning from './core/cleaning'; import * as Validation from './core/validation'; import * as Analysis from './core/analysis'; import * as Manipulation from './core/manipulation'; import * as Encoding from './core/encoding'; import * as Advanced from './core/advanced'; import { StringCoreImpl } from './plugins/plugin-interface'; // Chainable API class ChainableStringImpl { constructor(str) { this.str = str; } // Case transformations toCamelCase() { return new ChainableStringImpl(Case.toCamelCase(this.str)); } toPascalCase() { return new ChainableStringImpl(Case.toPascalCase(this.str)); } toSnakeCase() { return new ChainableStringImpl(Case.toSnakeCase(this.str)); } toKebabCase() { return new ChainableStringImpl(Case.toKebabCase(this.str)); } toConstantCase() { return new ChainableStringImpl(Case.toConstantCase(this.str)); } toTitleCase(locale) { return new ChainableStringImpl(Case.toTitleCase(this.str, locale)); } toSentenceCase() { return new ChainableStringImpl(Case.toSentenceCase(this.str)); } toLowerCase() { return new ChainableStringImpl(this.str.toLowerCase()); } toUpperCase() { return new ChainableStringImpl(this.str.toUpperCase()); } // Cleaning trim(chars) { return new ChainableStringImpl(Cleaning.trim(this.str, chars)); } trimStart(chars) { return new ChainableStringImpl(Cleaning.trimStart(this.str, chars)); } trimEnd(chars) { return new ChainableStringImpl(Cleaning.trimEnd(this.str, chars)); } removeExtraSpaces() { return new ChainableStringImpl(Cleaning.removeExtraSpaces(this.str)); } normalizeWhitespace() { return new ChainableStringImpl(Cleaning.normalizeWhitespace(this.str)); } removeNonPrintable() { return new ChainableStringImpl(Cleaning.removeNonPrintable(this.str)); } stripHtml() { return new ChainableStringImpl(Cleaning.stripHtml(this.str)); } stripAnsi() { return new ChainableStringImpl(Cleaning.stripAnsi(this.str)); } removeAccents() { return new ChainableStringImpl(Cleaning.removeAccents(this.str)); } // Manipulation reverse() { return new ChainableStringImpl(Manipulation.reverse(this.str)); } shuffle() { return new ChainableStringImpl(Manipulation.shuffle(this.str)); } repeat(count, separator) { return new ChainableStringImpl(Manipulation.repeat(this.str, count, separator)); } truncate(length, options) { return new ChainableStringImpl(Manipulation.truncate(this.str, length, options)); } pad(length, fillString, type) { return new ChainableStringImpl(Manipulation.pad(this.str, length, fillString, type)); } wrap(width, options) { return new ChainableStringImpl(Manipulation.wrap(this.str, width, options)); } slugify(options) { return new ChainableStringImpl(Manipulation.slugify(this.str, options)); } // Encoding encodeBase64() { return new ChainableStringImpl(Encoding.encodeBase64(this.str)); } decodeBase64() { return new ChainableStringImpl(Encoding.decodeBase64(this.str)); } encodeHex() { return new ChainableStringImpl(Encoding.encodeHex(this.str)); } decodeHex() { return new ChainableStringImpl(Encoding.decodeHex(this.str)); } encodeHtml() { return new ChainableStringImpl(Encoding.encodeHtml(this.str)); } decodeHtml() { return new ChainableStringImpl(Encoding.decodeHtml(this.str)); } encodeUri() { return new ChainableStringImpl(Encoding.encodeUri(this.str)); } decodeUri() { return new ChainableStringImpl(Encoding.decodeUri(this.str)); } // Advanced mask(options) { return new ChainableStringImpl(Advanced.mask(this.str, options)); } value() { return this.str; } } // Static Class API export class Str { } // Case transformations Str.toCamelCase = Case.toCamelCase; Str.toPascalCase = Case.toPascalCase; Str.toSnakeCase = Case.toSnakeCase; Str.toKebabCase = Case.toKebabCase; Str.toConstantCase = Case.toConstantCase; Str.toTitleCase = Case.toTitleCase; Str.toSentenceCase = Case.toSentenceCase; // Cleaning Str.trim = Cleaning.trim; Str.trimStart = Cleaning.trimStart; Str.trimEnd = Cleaning.trimEnd; Str.removeExtraSpaces = Cleaning.removeExtraSpaces; Str.normalizeWhitespace = Cleaning.normalizeWhitespace; Str.removeNonPrintable = Cleaning.removeNonPrintable; Str.stripHtml = Cleaning.stripHtml; Str.stripAnsi = Cleaning.stripAnsi; Str.removeAccents = Cleaning.removeAccents; // Validation Str.isEmail = Validation.isEmail; Str.isUrl = Validation.isUrl; Str.isUuid = Validation.isUuid; Str.isHexColor = Validation.isHexColor; Str.isBase64 = Validation.isBase64; Str.isJson = Validation.isJson; Str.isNumeric = Validation.isNumeric; Str.isAlpha = Validation.isAlpha; Str.isAlphanumeric = Validation.isAlphanumeric; Str.isEmpty = Validation.isEmpty; // Analysis Str.contains = Analysis.contains; Str.count = Analysis.count; Str.indexOfAll = Analysis.indexOfAll; Str.words = Analysis.words; Str.chars = Analysis.chars; Str.codePoints = Analysis.codePoints; Str.graphemes = Analysis.graphemes; // Manipulation Str.reverse = Manipulation.reverse; Str.shuffle = Manipulation.shuffle; Str.repeat = Manipulation.repeat; Str.truncate = Manipulation.truncate; Str.pad = Manipulation.pad; Str.wrap = Manipulation.wrap; Str.slugify = Manipulation.slugify; // Encoding Str.encodeBase64 = Encoding.encodeBase64; Str.decodeBase64 = Encoding.decodeBase64; Str.encodeHex = Encoding.encodeHex; Str.decodeHex = Encoding.decodeHex; Str.encodeHtml = Encoding.encodeHtml; Str.decodeHtml = Encoding.decodeHtml; Str.encodeUri = Encoding.encodeUri; Str.decodeUri = Encoding.decodeUri; // Advanced Str.similarity = Advanced.similarity; Str.fuzzyMatch = Advanced.fuzzyMatch; Str.soundsLike = Advanced.soundsLike; Str.findPatterns = Advanced.findPatterns; Str.isRepeating = Advanced.isRepeating; Str.extractEmails = Advanced.extractEmails; Str.extractUrls = Advanced.extractUrls; Str.extractNumbers = Advanced.extractNumbers; Str.random = Advanced.random; Str.generatePronounceable = Advanced.generatePronounceable; Str.generateFromPattern = Advanced.generateFromPattern; Str.mask = Advanced.mask; Str.maskEmail = Advanced.maskEmail; Str.maskCreditCard = Advanced.maskCreditCard; Str.hash = Advanced.hash; Str.toTable = Advanced.toTable; Str.boxify = Advanced.boxify; Str.progressBar = Advanced.progressBar; // Chainable factory function export function chain(str) { return new ChainableStringImpl(str); } // Plugin core instance export const core = new StringCoreImpl(); // Default export for convenience export default { ...Case, ...Cleaning, ...Validation, ...Analysis, ...Manipulation, ...Encoding, ...Advanced, Str, chain, core };