Skip to content

Commit

Permalink
Added splitCamelCase to kebab to ensure a camel cased string can be k…
Browse files Browse the repository at this point in the history
…ebab cased
  • Loading branch information
TheSpicyMeatball committed Nov 9, 2021
1 parent 5065fcd commit 0943d70
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.13.1] - 2021-11-09
- Added splitCamelCase to kebab to ensure a camel cased string can be kebab cased

## [1.13.0] - 2021-11-03
- Added keyPressed utils; performance improvements (findLastIndex, insertAt, removeIf)

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[![Build Status](https://travis-ci.com/TheSpicyMeatball/utils.svg?branch=main)](https://travis-ci.com/TheSpicyMeatball/utils)
[![Coverage Status](https://coveralls.io/repos/github/TheSpicyMeatball/utils/badge.svg?branch=main)](https://coveralls.io/github/TheSpicyMeatball/utils?branch=main)
[![dependencies Status](https://status.david-dm.org/gh/TheSpicyMeatball/utils.svg)](https://david-dm.org/TheSpicyMeatball/utils)

# @paravano/utils

Expand All @@ -10,7 +9,7 @@
import { isNilOrEmpty, take } from '@paravano/utils';
```

<p><b>Version:</b> 1.13.0</p>
<p><b>Version:</b> 1.13.1</p>

> Click on each function name for details and examples
Expand Down
3 changes: 3 additions & 0 deletions dist/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.13.1] - 2021-11-09
- Added splitCamelCase to kebab to ensure a camel cased string can be kebab cased

## [1.13.0] - 2021-11-03
- Added keyPressed utils; performance improvements (findLastIndex, insertAt, removeIf)

Expand Down
2 changes: 1 addition & 1 deletion dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { isNilOrEmpty, take } from '@paravano/utils';
```

<p><b>Version:</b> 1.13.0</p>
<p><b>Version:</b> 1.13.1</p>

> Click on each function name for details and examples
Expand Down
2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paravano/utils",
"version": "1.13.0",
"version": "1.13.1",
"description": "A set of JavaScript utils",
"main": "lib/es5/index.js",
"module": "lib/es6/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/string/kebab/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('kebab', () => {
expect(kebab('$@__HELLO+WORLD__')).toBe('hello-world');
expect(kebab('2Hello 7world')).toBe('hello-7-world');
expect(kebab('2Hello 7wo25rld')).toBe('hello-7-wo-25-rld');
expect(kebab('helloWorld')).toBe('hello-world');
});

test('empty', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/string/kebab/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { first } from '../../array/first';
import { isString } from '../../type/isString';
import { isNilOrEmpty } from "../../value/isNilOrEmpty";
import { splitCamelCase } from '../splitCamelCase';

/**
* Converts the string to kebab case
Expand All @@ -18,7 +19,7 @@ import { isNilOrEmpty } from "../../value/isNilOrEmpty";
export const kebab = (value: string) : string => {
if (isNilOrEmpty(value) || !isString(value)) return '';

const matches = Array.from(value.matchAll(/(?:[a-zA-Z])+.*[0-9]*/g));
const matches = Array.from(splitCamelCase(value).matchAll(/(?:[a-zA-Z])+.*[0-9]*/g));

// Remove special chars, insert basic dashes, make lower case, remove spaces
const output = first(first(first(matches), '').replace(/[^a-zA-Z0-9]/g, '-').toLowerCase().match(/(?:(?:[a-zA-Z0-9])+-*(?:[a-zA-Z0-9]))*/g), '');
Expand Down

0 comments on commit 0943d70

Please sign in to comment.