Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cerebrusinc/fstring

This brings Python string manipulation to js!
https://github.com/cerebrusinc/fstring

javascript nodejs package typescript

Last synced: about 1 month ago
JSON representation

This brings Python string manipulation to js!

Awesome Lists containing this project

README

        


py-qol logo

# fstring

This package brings some Python string formatting to Javascript! Currently you can:

- Abbreviate a string
- Make a string sentence case
- Make a string title case

# Installation

npm install @techtronics/fstring

or

yarn add @techtronics/fstring

It goes hand in hand with our quality of life package [qol](https://github.com/lewisjr/qol)

# Importing

```javascript
// ES6 Module
import * as fstring from "@techtronics/fstring";

// ES6 Destructuring
import { abbreviate, toTitleCase, toSentenceCase } from "@techtronics/fstring";

// ES5 Module
const fstring = require("@techtronics/fstring");

// ES5 Destructuring
const {
abbreviate,
toTitleCase,
toSentenceCase,
} = require("@techtronics/fstring");
```

# Usage

```javascript
const sentence = "heLLo wOrLD, mY NAME is lEwis; i am a Developer.";
const name = "lEwiS mOsho junior";

console.log(toSentenceCase(sentence));
// Hello world, my name is lewis; I am a developer.

console.log(toTitleCase(name));
// Lewis Mosho Junior

console.log(abbreviate(name));
// LMJ
```

# Functions

## abbreviate

Make an **abbreviation** of a string; Usually used for names. It returns a capital case abbreviation of the string.

Params

| Parameter | Default Setting | Required? | Definition |
| --------- | --------------- | --------- | ----------------------------------------------------------- |
| txt | `null` | Yes | The string you wish to abbreviate |
| delimiter | `" "` | No | The character or string that seperates words in the string |
| reverse | `false` | No | An option to enable you to request a reversed return string |

## toTitleCase

Make any string **title cased**. it returns a string in which every first letter of a word is upper cased with the rest being lower cased.

Params

| Parameter | Default Setting | Required? | Definition |
| --------- | --------------- | --------- | ---------------------------------------------------------- |
| txt | `null` | Yes | The string you wish to change to title case |
| delimiter | `" "` | No | The character or string that seperates words in the string |

## toSentenceCase

Make any string **sentence cased**; The current sentence delimiters are:

- `.`
- `;`
- `:`
- `!`
- `?`

It returns a string in which every first letter of the first word of a sentence is capitalised, with the reaminder of the senter being lower cased.

Params

| Parameter | Default Setting | Required? | Definition |
| --------- | --------------- | --------- | ---------------------------------------------------------- |
| txt | `null` | Yes | The string you wish to change to sentence case |
| delimiter | `" "` | No | The character or string that seperates words in the string |

# Changelog

## v0.1.x

v0.1.5

- Moved from [@techtronics/fstring](https://www.npmjs.com/package/@techtronics/fstring)

v0.1.4

- Added colon support to `toSentenceCase`
- Full parity with our python quality of life [qolpy](https://github.com/lewisjr/qolpy) package

v0.1.3

- Fixed missing build and type annotations

v0.1.2

- Added the option to have the abbreviation reverse or not before return

v0.1.1

- Type hint updates
- README restructuring
- toSentenceCase now supports custom delimiters 😎

v0.1.0

- Initial release
- Sentence casing, title casing, and abrreviations added and typed