Skip to content

Commit 4a05169

Browse files
committed
feat: Initial implementation
0 parents  commit 4a05169

File tree

10 files changed

+148
-0
lines changed

10 files changed

+148
-0
lines changed

.github/workflows/test.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Tests
2+
on: [push, pull_request]
3+
4+
env:
5+
CI: true
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Setup Node.js
13+
uses: actions/setup-node@v1
14+
with:
15+
node-version: 14
16+
- run: npm install
17+
- name: Lint
18+
run: npm run -s pretest
19+
- name: Tests
20+
run: npm run -s tests-only
21+
- name: Coverage
22+
run: npm run -s posttest

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.tgz
2+
node_modules
3+
coverage

.npmignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.tgz
2+
.github
3+
nyc.config.js
4+
coverage
5+
test.js

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 CFWare, LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# @cfware/decamelize [![NPM Version][npm-image]][npm-url]
2+
3+
ES Module fork of [decamelize](github.com/sindresorhus/decamelize)
4+
5+
## Usage
6+
7+
```js
8+
import decamelize from '@cfware/decamelize';
9+
10+
console.log(decamelize('noTab'));
11+
// => no-tab
12+
13+
console.log(decamelize('testGUILabel'));
14+
// => test-gui-label
15+
```
16+
17+
[npm-image]: https://img.shields.io/npm/v/@cfware/decamelize.svg
18+
[npm-url]: https://npmjs.org/package/@cfware/decamelize

decamelize.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint "prefer-named-capture-group": 0 */
2+
/*
3+
MIT License
4+
5+
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
9+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
*/
13+
14+
export default function decamelize(text) {
15+
// Adopted from github.com/sindresorhus/decamelize
16+
// - Uses abbreviated unicode character classes
17+
// - Drop separator argument
18+
// - ES module format
19+
return text
20+
.replace(/([\p{Ll}\d])(\p{Lu})/gu, '$1-$2')
21+
.replace(/(\p{Lu}+)(\p{Lu}\p{Ll}+)/gu, '$1-$2')
22+
.toLowerCase();
23+
}

nyc.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from '@cfware/nyc';

package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "@cfware/decamelize",
3+
"version": "0.1.0",
4+
"description": "ES Module fork of decamelize",
5+
"type": "module",
6+
"main": "decamelize.js",
7+
"exports": "./decamelize.js",
8+
"scripts": {
9+
"pretest": "cfware-lint .",
10+
"tests-only": "nyc -s node --experimental-loader=@istanbuljs/esm-loader-hook test.js",
11+
"test": "npm run -s tests-only",
12+
"posttest": "nyc report --check-coverage"
13+
},
14+
"engines": {
15+
"node": ">=14.0.0"
16+
},
17+
"author": "Corey Farrell",
18+
"license": "MIT",
19+
"repository": {
20+
"type": "git",
21+
"url": "git+https://github.com/cfware/decamelize.git"
22+
},
23+
"bugs": {
24+
"url": "https://github.com/cfware/decamelize/issues"
25+
},
26+
"homepage": "https://github.com/cfware/decamelize#readme",
27+
"dependencies": {},
28+
"devDependencies": {
29+
"@cfware/lint": "^2.0.2",
30+
"@cfware/nyc": "^0.7.0",
31+
"@istanbuljs/esm-loader-hook": "^0.1.2",
32+
"libtap": "^0.3.0",
33+
"nyc": "^15.1.0"
34+
}
35+
}

test.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import t from 'libtap';
2+
3+
import decamelize from '@cfware/decamelize';
4+
5+
t.type(decamelize, 'function');
6+
7+
// These tests were adapted from github.com/sindresorhus/decamelize
8+
t.equal(decamelize(''), '');
9+
t.equal(decamelize('unicornsAndRainbows'), 'unicorns-and-rainbows');
10+
t.equal(decamelize('UNICORNS AND RAINBOWS'), 'unicorns and rainbows');
11+
t.equal(decamelize('unicorns-and-rainbows'), 'unicorns-and-rainbows');
12+
t.equal(decamelize('thisIsATest'), 'this-is-a-test');
13+
t.equal(decamelize('thisHasSpecialCharactersLikeČandŠ'), 'this-has-special-characters-like-čand-š');
14+
15+
t.equal(decamelize('myURLString'), 'my-url-string');
16+
t.equal(decamelize('URLString'), 'url-string');
17+
t.equal(decamelize('StringURL'), 'string-url');
18+
t.equal(decamelize('testGUILabel'), 'test-gui-label');
19+
t.equal(decamelize('CAPLOCKED1'), 'caplocked1');

0 commit comments

Comments
 (0)