0.1.0 • Published 2 years ago

@polymer-co/rope v0.1.0

Weekly downloads
-
License
MPL-2.0
Repository
github
Last release
2 years ago

Rope JS

Overview

npm install @polymer-co/rope

Rope JS extends the inbuilt JavaScript string type with additional helper methods. It's focus is to be simple and to not require wrapper classes - all you need to do is require it, and start using!

It includes super useful helper methods; from inserting strings, capitalizing, random sampling, and more! Rope JS also provides utilities for case conversion (ie, camel case to pascal), allowing you to convert from all the well-known casings to any other. Case conversions include:

CaseExampleLossy?
camelhelloWorldNo
camelSnakehello_WorldNo
cobolHELLO-WORLDNo
flathelloworldYes
kebabhello-worldNo
macroHELLO_WORLDNo
pascalHelloWorldNo
sarcastichElLo wOrLdNo
sentencehello, worldNo
snakehello_worldNo
trainHello-WorldNo
upperFlatHELLOWORLDYes

'Lossy' implies that word seperation will be lost when converting to this case. For example, converting from camel to flat will result in 'camelCase' being converted to 'camelcase' - the flat case output cannot be converted back into camelCase, as word seperation has not been preseved.

TypeScript types declaration files are included by default.

Installation

npm installation

To install on npm run npm install @polymer-co/rope

Static file installation

Download the most recent rope.js from the releases section on GitHub. Include the file as usual:

<html>
  <head>
    <script src='lib/path/rope.js'></script>
  </head>
</html>

Usage

For full API documentation, check the declaration file src/rope.ts.

If installed with npm

Within your entry point file (eg, main.ts or main.js), import rope:

import '@polymer-co/rope'

After importing, the extension methods should be usable in all other files.

If installed with static file

There should be no other action needed if installed via a static file.

Examples

The below examples do not include all available methods, it is meant to demonstrate general usage.

Convert from camel case to train case

"thisIsCamelCase".convertCase('camel', 'pascal') // "This-Is-Camel-Case

See src/rope.ts's Case type for a list of available case conversions.

Uppercase all words in a sentence

"test sentence to uppercase".uppercaseAll() // "Test Sentence To Uppercase"

Insert a word at a given position

"hi, are  there?".insert(8, "you") // "hi, are you there?

Return a list of characters

"hello".chars() // ['h', 'e', 'l', 'l', 'o']

Remove a portion of a string

"12345".remove(1, 3) // "15"