decamelize
Advanced tools
Comparing version 5.0.1 to 6.0.0
@@ -1,39 +0,37 @@ | ||
declare namespace decamelize { | ||
interface Options { | ||
/** | ||
Character or string inserted to separate words in `string`. | ||
export interface Options { | ||
/** | ||
Character or string inserted to separate words in `string`. | ||
@default '_' | ||
@default '_' | ||
@example | ||
``` | ||
import decamelize = require('decamelize'); | ||
@example | ||
``` | ||
import decamelize from 'decamelize'; | ||
decamelize('unicornRainbow'); | ||
//=> 'unicorn_rainbow' | ||
decamelize('unicornRainbow'); | ||
//=> 'unicorn_rainbow' | ||
decamelize('unicornRainbow', {separator: '-'}); | ||
//=> 'unicorn-rainbow' | ||
``` | ||
*/ | ||
readonly separator?: string; | ||
decamelize('unicornRainbow', {separator: '-'}); | ||
//=> 'unicorn-rainbow' | ||
``` | ||
*/ | ||
readonly separator?: string; | ||
/** | ||
Preserve sequences of uppercase characters. | ||
/** | ||
Preserve sequences of uppercase characters. | ||
@default false | ||
@default false | ||
@example | ||
``` | ||
import decamelize = require('decamelize'); | ||
@example | ||
``` | ||
import decamelize from 'decamelize'; | ||
decamelize('testGUILabel'); | ||
//=> 'test_gui_label' | ||
decamelize('testGUILabel'); | ||
//=> 'test_gui_label' | ||
decamelize('testGUILabel', {preserveConsecutiveUppercase: true}); | ||
//=> 'test_GUI_label' | ||
``` | ||
*/ | ||
readonly preserveConsecutiveUppercase?: boolean; | ||
} | ||
decamelize('testGUILabel', {preserveConsecutiveUppercase: true}); | ||
//=> 'test_GUI_label' | ||
``` | ||
*/ | ||
readonly preserveConsecutiveUppercase?: boolean; | ||
} | ||
@@ -48,3 +46,3 @@ | ||
``` | ||
import decamelize = require('decamelize'); | ||
import decamelize from 'decamelize'; | ||
@@ -58,4 +56,2 @@ decamelize('unicornRainbow'); | ||
*/ | ||
declare function decamelize(string: string, options?: decamelize.Options): string; | ||
export = decamelize; | ||
export default function decamelize(string: string, options?: Options): string; |
28
index.js
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
const handlePreserveConsecutiveUppercase = (decamelized, separator) => { | ||
@@ -10,5 +8,3 @@ // Lowercase all single uppercase characters. As we | ||
/((?<![\p{Uppercase_Letter}\d])[\p{Uppercase_Letter}\d](?![\p{Uppercase_Letter}\d]))/gu, | ||
$0 => { | ||
return $0.toLowerCase(); | ||
} | ||
$0 => $0.toLowerCase(), | ||
); | ||
@@ -20,18 +16,16 @@ | ||
/(\p{Uppercase_Letter}+)(\p{Uppercase_Letter}\p{Lowercase_Letter}+)/gu, | ||
(_, $1, $2) => { | ||
return $1 + separator + $2.toLowerCase(); | ||
} | ||
(_, $1, $2) => $1 + separator + $2.toLowerCase(), | ||
); | ||
}; | ||
module.exports = ( | ||
export default function decamelize( | ||
text, | ||
{ | ||
separator = '_', | ||
preserveConsecutiveUppercase = false | ||
} = {} | ||
) => { | ||
preserveConsecutiveUppercase = false, | ||
} = {}, | ||
) { | ||
if (!(typeof text === 'string' && typeof separator === 'string')) { | ||
throw new TypeError( | ||
'The `text` and `separator` arguments should be of type `string`' | ||
'The `text` and `separator` arguments should be of type `string`', | ||
); | ||
@@ -52,3 +46,3 @@ } | ||
/([\p{Lowercase_Letter}\d])(\p{Uppercase_Letter})/gu, | ||
replacement | ||
replacement, | ||
); | ||
@@ -61,9 +55,9 @@ | ||
// Split multiple uppercase characters followed by one or more lowercase characters. | ||
// `my_URLstring` → `my_url_string` | ||
// `my_URLstring` → `my_ur_lstring` | ||
return decamelized | ||
.replace( | ||
/(\p{Uppercase_Letter})(\p{Uppercase_Letter}\p{Lowercase_Letter}+)/gu, | ||
replacement | ||
replacement, | ||
) | ||
.toLowerCase(); | ||
}; | ||
} |
{ | ||
"name": "decamelize", | ||
"version": "5.0.1", | ||
"version": "6.0.0", | ||
"description": "Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow", | ||
@@ -13,4 +13,6 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -37,6 +39,7 @@ "scripts": { | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.17.0", | ||
"typescript": "^4.4.3", | ||
"xo": "^0.44.0" | ||
} | ||
} |
@@ -10,5 +10,5 @@ # decamelize | ||
```sh | ||
npm install decamelize | ||
``` | ||
$ npm install decamelize | ||
``` | ||
@@ -18,3 +18,3 @@ ## Usage | ||
```js | ||
const decamelize = require('decamelize'); | ||
import decamelize from 'decamelize'; | ||
@@ -54,3 +54,3 @@ decamelize('unicornRainbow'); | ||
```js | ||
cosnt decamelize = require('decamelize'); | ||
import decamelize from 'decamelize'; | ||
@@ -72,3 +72,3 @@ decamelize('unicornRainbow'); | ||
```js | ||
const decamelize = require('decamelize'); | ||
import decamelize from 'decamelize'; | ||
@@ -75,0 +75,0 @@ decamelize('testGUILabel'); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
6843
4
93