Comparing version 1.0.0 to 2.0.0
40
index.js
@@ -1,24 +0,30 @@ | ||
/*! | ||
* pascalcase <https://github.com/jonschlinkert/pascalcase> | ||
* | ||
* Copyright (c) 2015-present, Jon ("Schlink") Schlinkert. | ||
* Licensed under the MIT License. | ||
*/ | ||
import camelcase from 'camelcase'; | ||
const titlecase = input => input[0].toLocaleUpperCase() + input.slice(1); | ||
const PUNCTUATION = /[^\p{L}\p{N}]+/ug; | ||
module.exports = value => { | ||
if (value === null || value === void 0) return ''; | ||
if (typeof value.toString !== 'function') return ''; | ||
const toString = input => { | ||
if (input == null) return ''; | ||
let input = value.toString().trim(); | ||
if (input === '') return ''; | ||
if (input.length === 1) return input.toLocaleUpperCase(); | ||
if (Array.isArray(input)) { | ||
return input.map(s => s.toString().trim()).filter(s => s.length > 0).join(' '); | ||
} | ||
let match = input.match(/[a-zA-Z0-9]+/g); | ||
if (match) { | ||
return match.map(m => titlecase(m)).join(''); | ||
if (typeof input === 'function') { | ||
return input.name ? input.name : ''; | ||
} | ||
return input; | ||
if (typeof input.toString !== 'function') { | ||
return ''; | ||
} | ||
return input.toString().trim(); | ||
}; | ||
export const pascalcase = (value, options = {}) => { | ||
const input = toString(value); | ||
const regex = options.punctuationRegex ?? PUNCTUATION; | ||
const output = input ? camelcase(regex ? input.replace(regex, ' ') : input, options) : ''; | ||
return output ? output[0].toLocaleUpperCase(options.locale) + output.slice(1) : ''; | ||
}; | ||
export default pascalcase; |
{ | ||
"name": "pascalcase", | ||
"description": "Convert a string to pascal-case.", | ||
"version": "1.0.0", | ||
"description": "Convert a string to pascal case (upper camelcase).", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/jonschlinkert/pascalcase", | ||
@@ -12,8 +12,9 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"license": "MIT", | ||
"type": "module", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js" | ||
], | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=14" | ||
}, | ||
@@ -25,5 +26,7 @@ "scripts": { | ||
"gulp-format-md": "^2.0.0", | ||
"mocha": "^6.2.0" | ||
"mocha": "^9.1.3" | ||
}, | ||
"keywords": [ | ||
"change case", | ||
"camel", | ||
"camelcase", | ||
@@ -37,2 +40,3 @@ "case", | ||
"string", | ||
"upper camel case", | ||
"UpperCamelCase" | ||
@@ -60,3 +64,6 @@ ], | ||
} | ||
}, | ||
"dependencies": { | ||
"camelcase": "^6.2.1" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# pascalcase [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/pascalcase.svg?style=flat)](https://www.npmjs.com/package/pascalcase) [![NPM monthly downloads](https://img.shields.io/npm/dm/pascalcase.svg?style=flat)](https://npmjs.org/package/pascalcase) [![NPM total downloads](https://img.shields.io/npm/dt/pascalcase.svg?style=flat)](https://npmjs.org/package/pascalcase) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/pascalcase.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/pascalcase) | ||
# pascalcase [![NPM version](https://img.shields.io/npm/v/pascalcase.svg?style=flat)](https://www.npmjs.com/package/pascalcase) [![NPM monthly downloads](https://img.shields.io/npm/dm/pascalcase.svg?style=flat)](https://npmjs.org/package/pascalcase) [![NPM total downloads](https://img.shields.io/npm/dt/pascalcase.svg?style=flat)](https://npmjs.org/package/pascalcase) [![Tests](https://github.com/jonschlinkert/pascalcase/actions/workflows/main.yml/badge.svg)](https://github.com/jonschlinkert/pascalcase/actions/workflows/main.yml) | ||
> Convert a string to pascal-case. | ||
> Convert a string to pascal case (upper camelcase). | ||
@@ -9,3 +9,3 @@ Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. | ||
Install with [npm](https://www.npmjs.com/) (requires [Node.js](https://nodejs.org/en/) >=8): | ||
Install with [npm](https://www.npmjs.com/) (requires [Node.js](https://nodejs.org/en/) >=14): | ||
@@ -16,6 +16,12 @@ ```sh | ||
## Prerequisites | ||
Requires [Node.js](https://nodejs.org/en/) version >= 14. | ||
## Usage | ||
```js | ||
const pascalcase = require('pascalcase'); | ||
import pascalcase from 'pascalcase'; | ||
// or the following if you prefer | ||
import { pascalcase } from 'pascalcase'; | ||
@@ -36,2 +42,18 @@ console.log(pascalcase('a')); //=> 'A' | ||
## Uppercase character sequences | ||
If you wish to preserve upper case character sequences, you may pass an options object with the `preserveConsecutiveUppercase` option set to `true`: | ||
```js | ||
console.log(pascalcase('The IRS Is Mean')); //=> 'TheIrsIsMean | ||
console.log(pascalcase('The IRS Is Mean', { preserveConsecutiveUppercase: true })); //=> TheIRSIsMean | ||
console.log(pascalcase('We saw a UFO')); //=> WeSawAUfo | ||
console.log(pascalcase('We saw a UFO', { preserveConsecutiveUppercase: true })); //=> WeSawAUFO | ||
``` | ||
## Options | ||
All options are passed to [sindresorhus/camelcase](https://github.com/sindresorhus/camelcase), please visit that project to learn about all available options. | ||
## About | ||
@@ -89,3 +111,3 @@ | ||
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Copyright © 2021, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT License](LICENSE). | ||
@@ -95,2 +117,2 @@ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on August 08, 2019._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on December 29, 2021._ |
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
8289
22
113
Yes
1
+ Addedcamelcase@^6.2.1
+ Addedcamelcase@6.3.0(transitive)