Skip to content

Commit

Permalink
Documentation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pedsmoreira committed Jan 13, 2024
1 parent 2b87038 commit 9a06262
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 56 deletions.
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# 4.0.0

* Updated function signature to use named arguments for better clarity
* Use ESM instead of UMD
* Update from default to named export
* Converted from Flow to Typescript
- Updated function signature to use named arguments for better clarity
- Use ESM instead of UMD
- Update from default to named export
- Converted from Flow to Typescript

# 3.0.0

* Added special letters: `*` and `-`
- Added special letters: `*` and `-`

# 2.0.0

* Updated casex to use `'A-Z\\s_-'` delimiters instead of accepting only letters and numbers.
- Updated casex to use `'A-Z\\s_-'` delimiters instead of accepting only letters and numbers.

# 1.0.1

* Replaced arrow function with normal function to avoid bundling issues
- Replaced arrow function with normal function to avoid bundling issues

# 1.0.0

* Numbers are not treated as lowercase letters
* Fix issue with upper case characters not followed by other characters
- Numbers are not treated as lowercase letters
- Fix issue with upper case characters not followed by other characters
92 changes: 46 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All in one, self expressive pattern for string case styles

## Introduction

casex is a function that applies a case style given a pattern.
`casex` is a function that applies a case style given a pattern.

Instead of having a specific function for each case style, I provide a self-expressive pattern that represent the desired output. For example, kebab-case can be represented as `ca-se` and title case as `Ca Se`.

Expand All @@ -17,32 +17,32 @@ npm install --save casex
## Usage

```js
import { casex } from 'casex';
import { casex } from "casex";

casex({ text: 'your text', pattern: 'ca-se' }) // your-text
casex({ text: "your text", pattern: "ca-se" }); // your-text
```

## How it works

### 1. Breaking text into words

By default, casex uses capitalizations (`A-Z`), `-`, `_` and spaces (`\s`) to break the text into words.
By default, `casex` uses capitalizations (`A-Z`), `-`, `_` and spaces (`\s`) to break the text into words.

Let's take for example `i_am the-real JohnDoe`:

* `i`: 1st word
* `am`: 2nd+ word
* `the`: 2nd+ word
* `real`: 2nd+ word
* `John`: 2nd+ word
* `Doe`: 2nd+ word
- `i`: 1st word
- `am`: 2nd+ word
- `the`: 2nd+ word
- `real`: 2nd+ word
- `John`: 2nd+ word
- `Doe`: 2nd+ word

#### 1.1 Custom delimiters

The default will likely work for most of your cases, but if you wish, you can provide custom delimiters:

```js
casex({ text: 'foo.bar,baz', pattern: 'Ca Se', delimiters: '.,' }); // Foo Bar Baz
casex({ text: "foo.bar,baz", pattern: "Ca Se", delimiters: ".," }); // Foo Bar Baz
```

_Note: The default delimiters are: `A-Z\\s_-`.
Expand All @@ -51,91 +51,91 @@ _Note: The default delimiters are: `A-Z\\s_-`.

Let's take for example `Ca_se`:

* `C`: first letter of the first word
* `a`: second and subsequent letters of the first word
* `_`: anything between the first two and last two letters is `glue` and will be repeted between words
* `s`: first letter of the second and subsequent words
* `e`: second and subsequent letters of the second and subsequent words
- `C`: first letter of the first word
- `a`: second and subsequent letters of the first word
- `_`: anything between the first two and last two letters is `glue` and will be repeted between words
- `s`: first letter of the second and subsequent words
- `e`: second and subsequent letters of the second and subsequent words

_Note: You can use any other letters to describe the pattern, such as `aa$aa` or `na_me`. What matters is that it takes the first two and last two letters for checking capitalization and whatever is in the middle is "glue"._

#### 2.1 Special transformations

Besides using lower and uppercase letters, you can also use:

* `*`: Do not change word
* `-`: Remove word
- `*`: Do not change word
- `-`: Remove word

## Examples

For these examples I'll use the text `i_am the-real JohnDoe`

**lowercase**

* Pattern: case
* Output: iamtherealjohndoe
- Pattern: case
- Output: iamtherealjohndoe

**UPPERCASE**

* Pattern: CASE
* Output: IAMTHEREALJOHNDOE
- Pattern: CASE
- Output: IAMTHEREALJOHNDOE

**snake_case**

* Pattern: ca_se
* Output: i_am_the_real_john_doe
- Pattern: ca_se
- Output: i_am_the_real_john_doe

**spinal-case**

* Pattern: ca-se
* Output: i-am-the-real-john-doe
- Pattern: ca-se
- Output: i-am-the-real-john-doe

**camelCase**

* Pattern: caSe
* Output: iAmTheRealJohnDoe
- Pattern: caSe
- Output: iAmTheRealJohnDoe

**UpperCamelCase**

* Pattern: CaSe
* Output: IAmTheRealJohnDoe
- Pattern: CaSe
- Output: IAmTheRealJohnDoe

**Sentence case**

* Pattern: Ca se
* Output: I am the real john doe
- Pattern: Ca se
- Output: I am the real john doe

**Title Case**

* Pattern: Ca Se
* Output: I Am The Real John Doe
- Pattern: Ca Se
- Output: I Am The Real John Doe

**Weird Example**

* Pattern: Ca12 34Se
* Output: I12 34Am12 34The12 34Real12 34John12 34Doe
- Pattern: Ca12 34Se
- Output: I12 34Am12 34The12 34Real12 34John12 34Doe

### Examples with special characters

**Capitalize first letter**

* Pattern: C\* \*\*
* Output: I am the real John Doe
- Pattern: C\* \*\*
- Output: I am the real John Doe

**Initials**

* Input: John Doe
* Pattern: C-S-
* Output: JD
- Input: John Doe
- Pattern: C-S-
- Output: JD

## Previous versions

Although for most cases it will work just fine, casex 4.x is not fully compatible previous versions. If you need previous docs please refer to:
Although for most cases it will work just fine, `casex` 4.x is not fully compatible previous versions. If you need previous docs please refer to:

* [v0.x](https://github.com/pedsmoreira/casex/tree/0.x)
* [v1.x](https://github.com/pedsmoreira/casex/tree/1.x)
* [v2.x](https://github.com/pedsmoreira/casex/tree/2.x)
* [v3.x](https://github.com/pedsmoreira/casex/tree/3.x)
- [v0.x](https://github.com/pedsmoreira/casex/tree/0.x)
- [v1.x](https://github.com/pedsmoreira/casex/tree/1.x)
- [v2.x](https://github.com/pedsmoreira/casex/tree/2.x)
- [v3.x](https://github.com/pedsmoreira/casex/tree/3.x)

## License

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"build": "tsup --entry.casex src/casex.ts --dts --format esm --minify",
"build:watch": "yarn build --watch",
"typecheck": "tsc --noEmit src/casex.ts",
"format": "prettier ./src/**/* --write",
"format": "prettier ./src/**/* --write; prettier ./*.md --write",
"test": "vitest",
"postversion": "git push && git push --tags",
"ci:check": "yarn check",
Expand Down

0 comments on commit 9a06262

Please sign in to comment.