-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 10 and drop
xregexp
dependency (#22)
- Loading branch information
1 parent
eda5b74
commit 7ac6111
Showing
4 changed files
with
18 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,3 @@ language: node_js | |
node_js: | ||
- '12' | ||
- '10' | ||
- '8' | ||
- '6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,20 @@ | ||
declare const decamelize: { | ||
/** | ||
Convert a camelized string into a lowercased one with a custom separator: `unicornRainbow` → `unicorn_rainbow`. | ||
/** | ||
Convert a camelized string into a lowercased one with a custom separator: `unicornRainbow` → `unicorn_rainbow`. | ||
@param string - The camelcase string to decamelize. | ||
@param separator - The separator to use to put in between the words from `string`. Default: `'_'`. | ||
@param string - The camelcase string to decamelize. | ||
@param separator - The separator to use to put in between the words from `string`. Default: `'_'`. | ||
@example | ||
``` | ||
import decamelize = require('decamelize'); | ||
@example | ||
``` | ||
import decamelize = require('decamelize'); | ||
decamelize('unicornRainbow'); | ||
//=> 'unicorn_rainbow' | ||
decamelize('unicornRainbow'); | ||
//=> 'unicorn_rainbow' | ||
decamelize('unicornRainbow', '-'); | ||
//=> 'unicorn-rainbow' | ||
``` | ||
*/ | ||
(string: string, separator?: string): string; | ||
|
||
// TODO: Remove this for the next major release, refactor the whole definition to: | ||
// declare function decamelize(string: string, separator?: string): string; | ||
// export = decamelize; | ||
default: typeof decamelize; | ||
}; | ||
decamelize('unicornRainbow', '-'); | ||
//=> 'unicorn-rainbow' | ||
``` | ||
*/ | ||
declare function decamelize(string: string, separator?: string): string; | ||
|
||
export = decamelize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,12 @@ | ||
'use strict'; | ||
const xRegExp = require('xregexp'); | ||
|
||
const decamelize = (text, separator = '_') => { | ||
module.exports = (text, separator = '_') => { | ||
if (!(typeof text === 'string' && typeof separator === 'string')) { | ||
throw new TypeError('The `text` and `separator` arguments should be of type `string`'); | ||
} | ||
|
||
const regex1 = xRegExp('([\\p{Ll}\\d])(\\p{Lu})', 'g'); | ||
const regex2 = xRegExp('(\\p{Lu}+)(\\p{Lu}[\\p{Ll}\\d]+)', 'g'); | ||
|
||
return text | ||
// TODO: Use this instead of `xregexp` when targeting Node.js 10: | ||
// .replace(/([\p{Lowercase_Letter}\d])(\p{Uppercase_Letter})/gu, `$1${separator}$2`) | ||
// .replace(/(\p{Lowercase_Letter}+)(\p{Uppercase_Letter}[\p{Lowercase_Letter}\d]+)/gu, `$1${separator}$2`) | ||
.replace(regex1, `$1${separator}$2`) | ||
.replace(regex2, `$1${separator}$2`) | ||
.replace(/([\p{Lowercase_Letter}\d])(\p{Uppercase_Letter})/gu, `$1${separator}$2`) | ||
.replace(/(\p{Uppercase_Letter}+)(\p{Uppercase_Letter}[\p{Lowercase_Letter}\d]+)/gu, `$1${separator}$2`) | ||
.toLowerCase(); | ||
}; | ||
|
||
module.exports = decamelize; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = decamelize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters