Socket
Socket
Sign inDemoInstall

change-case

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

change-case - npm Package Compare versions

Comparing version 5.2.0 to 5.3.0

3

dist/index.d.ts

@@ -19,2 +19,3 @@ /**

prefixCharacters?: string;
suffixCharacters?: string;
}

@@ -30,3 +31,3 @@ /**

*/
export declare function split(input: string, options?: SplitOptions): string[];
export declare function split(value: string, options?: SplitOptions): string[];
/**

@@ -33,0 +34,0 @@ * Convert a string to space separated lower case (`foo bar`).

@@ -11,8 +11,8 @@ // Regexps involved with splitting words in various case formats.

// The default characters to keep after transforming case.
const DEFAULT_PREFIX_CHARACTERS = "";
const DEFAULT_PREFIX_SUFFIX_CHARACTERS = "";
/**
* Split any cased input strings into an array of words.
*/
export function split(input, options) {
let result = input.trim();
export function split(value, options) {
let result = value.trim();
result = result

@@ -42,7 +42,8 @@ .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)

export function noCase(input, options) {
const prefix = getPrefix(input, options?.prefixCharacters);
const [prefix, value, suffix] = splitPrefixSuffix(input, options);
return (prefix +
split(input, options)
split(value, options)
.map(lowerFactory(options?.locale))
.join(options?.delimiter ?? " "));
.join(options?.delimiter ?? " ") +
suffix);
}

@@ -53,3 +54,3 @@ /**

export function camelCase(input, options) {
const prefix = getPrefix(input, options?.prefixCharacters);
const [prefix, value, suffix] = splitPrefixSuffix(input, options);
const lower = lowerFactory(options?.locale);

@@ -61,3 +62,3 @@ const upper = upperFactory(options?.locale);

return (prefix +
split(input, options)
split(value, options)
.map((word, index) => {

@@ -68,3 +69,4 @@ if (index === 0)

})
.join(options?.delimiter ?? ""));
.join(options?.delimiter ?? "") +
suffix);
}

@@ -75,3 +77,3 @@ /**

export function pascalCase(input, options) {
const prefix = getPrefix(input, options?.prefixCharacters);
const [prefix, value, suffix] = splitPrefixSuffix(input, options);
const lower = lowerFactory(options?.locale);

@@ -83,5 +85,6 @@ const upper = upperFactory(options?.locale);

return (prefix +
split(input, options)
split(value, options)
.map(transform)
.join(options?.delimiter ?? ""));
.join(options?.delimiter ?? "") +
suffix);
}

@@ -98,9 +101,10 @@ /**

export function capitalCase(input, options) {
const prefix = getPrefix(input, options?.prefixCharacters);
const [prefix, value, suffix] = splitPrefixSuffix(input, options);
const lower = lowerFactory(options?.locale);
const upper = upperFactory(options?.locale);
return (prefix +
split(input, options)
split(value, options)
.map(capitalCaseTransformFactory(lower, upper))
.join(options?.delimiter ?? " "));
.join(options?.delimiter ?? " ") +
suffix);
}

@@ -111,7 +115,8 @@ /**

export function constantCase(input, options) {
const prefix = getPrefix(input, options?.prefixCharacters);
const [prefix, value, suffix] = splitPrefixSuffix(input, options);
return (prefix +
split(input, options)
split(value, options)
.map(upperFactory(options?.locale))
.join(options?.delimiter ?? "_"));
.join(options?.delimiter ?? "_") +
suffix);
}

@@ -140,3 +145,3 @@ /**

export function sentenceCase(input, options) {
const prefix = getPrefix(input, options?.prefixCharacters);
const [prefix, value, suffix] = splitPrefixSuffix(input, options);
const lower = lowerFactory(options?.locale);

@@ -146,3 +151,3 @@ const upper = upperFactory(options?.locale);

return (prefix +
split(input, options)
split(value, options)
.map((word, index) => {

@@ -153,3 +158,4 @@ if (index === 0)

})
.join(options?.delimiter ?? " "));
.join(options?.delimiter ?? " ") +
suffix);
}

@@ -188,15 +194,26 @@ /**

}
function getPrefix(input, prefixCharacters = DEFAULT_PREFIX_CHARACTERS) {
let prefix = "";
for (let i = 0; i < input.length; i++) {
const char = input.charAt(i);
if (prefixCharacters.includes(char)) {
prefix += char;
}
else {
function splitPrefixSuffix(input, options) {
const prefixCharacters = options?.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
const suffixCharacters = options?.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
let prefixIndex = 0;
let suffixIndex = input.length;
while (prefixIndex < input.length) {
const char = input.charAt(prefixIndex);
if (!prefixCharacters.includes(char))
break;
}
prefixIndex++;
}
return prefix;
while (suffixIndex > prefixIndex) {
const index = suffixIndex - 1;
const char = input.charAt(index);
if (!suffixCharacters.includes(char))
break;
suffixIndex = index;
}
return [
input.slice(0, prefixIndex),
input.slice(prefixIndex, suffixIndex),
input.slice(suffixIndex),
];
}
//# sourceMappingURL=index.js.map
{
"name": "change-case",
"version": "5.2.0",
"version": "5.3.0",
"description": "Transform a string between `camelCase`, `PascalCase`, `Capital Case`, `snake_case`, `kebab-case`, `CONSTANT_CASE` and others",

@@ -5,0 +5,0 @@ "keywords": [

@@ -42,2 +42,3 @@ # Change Case

- `prefixCharacters?: string` Retain at the beginning of the string. Defaults to `""`. Example: use `"_"` to keep the underscores in `__typename`.
- `suffixCharacters?: string` Retain at the end of the string. Defaults to `""`. Example: use `"_"` to keep the underscore in `type_`.

@@ -44,0 +45,0 @@ By default, `pascalCase` and `snakeCase` separate ambiguous characters with `_`. For example, `V1.2` would become `V1_2` instead of `V12`. If you prefer them merged you can set `mergeAmbiguousCharacters` to `true`.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc