diff --git a/.travis.yml b/.travis.yml index e155464..94ab01f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,3 @@ language: node_js node_js: - '12' - '10' - - '8' - - '6' diff --git a/index.d.ts b/index.d.ts index 97f896e..a751feb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; diff --git a/index.js b/index.js index e383005..0861a6e 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/package.json b/package.json index b67d3e4..62fce4d 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=6" + "node": ">=10" }, "scripts": { "test": "xo && ava && tsd" @@ -32,9 +32,6 @@ "text", "convert" ], - "dependencies": { - "xregexp": "^4.2.4" - }, "devDependencies": { "ava": "^1.4.1", "tsd": "^0.7.2",