decamelize
Advanced tools
Comparing version 1.2.0 to 2.0.0
20
index.js
'use strict'; | ||
module.exports = function (str, sep) { | ||
if (typeof str !== 'string') { | ||
const xRegExp = require('xregexp'); | ||
module.exports = (text, separator) => { | ||
if (typeof text !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
} | ||
sep = typeof sep === 'undefined' ? '_' : sep; | ||
separator = typeof separator === 'undefined' ? '_' : separator; | ||
return str | ||
.replace(/([a-z\d])([A-Z])/g, '$1' + sep + '$2') | ||
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + sep + '$2') | ||
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`) | ||
.toLowerCase(); | ||
}; |
{ | ||
"name": "decamelize", | ||
"version": "1.2.0", | ||
"description": "Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow", | ||
"license": "MIT", | ||
"repository": "sindresorhus/decamelize", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"decamelize", | ||
"decamelcase", | ||
"camelcase", | ||
"lowercase", | ||
"case", | ||
"dash", | ||
"hyphen", | ||
"string", | ||
"str", | ||
"text", | ||
"convert" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "decamelize", | ||
"version": "2.0.0", | ||
"description": "Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow", | ||
"license": "MIT", | ||
"repository": "sindresorhus/decamelize", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"decamelize", | ||
"decamelcase", | ||
"camelcase", | ||
"lowercase", | ||
"case", | ||
"dash", | ||
"hyphen", | ||
"string", | ||
"str", | ||
"text", | ||
"convert" | ||
], | ||
"dependencies": { | ||
"xregexp": "4.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
@@ -10,3 +10,3 @@ # decamelize [![Build Status](https://travis-ci.org/sindresorhus/decamelize.svg?branch=master)](https://travis-ci.org/sindresorhus/decamelize) | ||
``` | ||
$ npm install --save decamelize | ||
$ npm install decamelize | ||
``` | ||
@@ -13,0 +13,0 @@ |
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
3324
17
1
+ Addedxregexp@4.0.0
+ Addedxregexp@4.0.0(transitive)