1.1.2 • Published 3 years ago

@hisorange/elastring v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

ElaString Logo

ElaString - Fluent Immutable String Transformation

Version Build Coverage Status GitHub license

Opionated fluent string transformations; You can use this package when the input is coming from a user or any other unregulated source, and you want to use the string in a normalized and formated way.

Getting Started


npm i @hisorange/elastring
# or
yarn add @hisorange/elastring

Examples


import { Elastring } from '@hisorange/elastring';

const str = new Elastring('ORMDriver');

console.log(str.snakeCase.toString()); // orm_driver
console.log(str.pascalCase.suffix('.html').toString()); // OrmDriver.html
console.log(str.upperCase.toString()); // ORMDRIVER
console.log(`${str.pathCase.prefix('../').suffix('.js')} at!`); // ../orm/driver.js at!

Transformations


FunInputOutputNormalized
singularchildchildrenx
pascalCaseela-stringElaStringx
pluralchildrenchild
camelCaseela stringelaString
kebabCaseElaStringela-string
snakeCaseElaStringela_string
dotCaseElaStringela.string
humanCaseela_stringEla string
titleCaseela_stringEla String
upperCaseela_stringELA_STRINGx
lowerCaseELA_STRINGela_stringx
capitalCaseela stringEla-stringx
vacuumCaseela stringelastringx
pathCaseela stringela/string
prefix()string.prefix('ela')elastringx
suffix()ela.suffix('string.js')elastring.jsx
stripExtension()elastring.jselastringx
reverseelastringgnirtsalex

Technicalities


TypeScript: Everything is written in typescript from the get go, so You can have the best DX possible :)

Normalization: Some transformer will normalize the string first, this is there to avoid the weird side effects of some format to format conversion.

Immutable: After initialization the strings are immutable, so every call will create a new instance with the expected format, this is useful behavior when a string need in multiple format but be aware this is a computation heavy solution, so it's not advised to be used a in a high performance demanding environments.

Versioning: SemVer! But be aware if there is a behavior change then it will break compatibility so the major release will be changed, currently running ~110 test to ensure consistency but there are always edge cases, so each edge case will be fixed with a major release to avoid ruining someones setup on that case.

Links


Changelog


1.1.x
  • Added the reverse transformation
  • Fixed the terrible readme mesh :v
1.0.0 - Initial Release