@augment-vir/common 18.1.1 → 19.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.typedSplit = exports.getAllIndexesOf = exports.escapeStringForRegExp = exports.replaceStringAtIndex = exports.camelCaseToKebabCase = exports.kebabCaseToCamelCase = exports.capitalizeFirstLetter = exports.splitIncludeSplit = exports.collapseWhiteSpace = exports.removeCommasFromNumberString = exports.removeColor = exports.removeAnsiEscapeCodes = exports.joinWithFinalConjunction = void 0;
|
|
3
|
+
exports.typedSplit = exports.getAllIndexesOf = exports.escapeStringForRegExp = exports.replaceStringAtIndex = exports.camelCaseToKebabCase = exports.isCase = exports.hasCase = exports.StringCaseEnum = exports.kebabCaseToCamelCase = exports.capitalizeFirstLetter = exports.splitIncludeSplit = exports.collapseWhiteSpace = exports.removeCommasFromNumberString = exports.removeColor = exports.removeAnsiEscapeCodes = exports.joinWithFinalConjunction = void 0;
|
|
4
4
|
const ansi_1 = require("./ansi");
|
|
5
5
|
const regexp_1 = require("./regexp");
|
|
6
6
|
/**
|
|
@@ -105,17 +105,56 @@ function kebabCaseToCamelCase(rawKebabCase, casingOptions = defaultCasingOptions
|
|
|
105
105
|
return maybeCapitalize(camelCase, casingOptions);
|
|
106
106
|
}
|
|
107
107
|
exports.kebabCaseToCamelCase = kebabCaseToCamelCase;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
var StringCaseEnum;
|
|
109
|
+
(function (StringCaseEnum) {
|
|
110
|
+
StringCaseEnum["Upper"] = "upper";
|
|
111
|
+
StringCaseEnum["Lower"] = "lower";
|
|
112
|
+
})(StringCaseEnum || (exports.StringCaseEnum = StringCaseEnum = {}));
|
|
113
|
+
/** Indicates whether the given string has different lower and upper case variants. */
|
|
114
|
+
function hasCase(input) {
|
|
115
|
+
return input.toLowerCase() !== input.toUpperCase();
|
|
111
116
|
}
|
|
117
|
+
exports.hasCase = hasCase;
|
|
118
|
+
/**
|
|
119
|
+
* Checks if the given string is exclusively of the specific case.
|
|
120
|
+
*
|
|
121
|
+
* Note that some characters have no casing, such as punctuation (they have no difference between
|
|
122
|
+
* upper and lower casings). By default, those letters always return `true` for this function,
|
|
123
|
+
* regardless of which `caseType` is provided. To instead return `false` for any such characters,
|
|
124
|
+
* pass in an options object and set blockNoCaseCharacters to true.
|
|
125
|
+
*/
|
|
126
|
+
function isCase(input, caseType, options) {
|
|
127
|
+
if (!input && options?.blockNoCaseCharacters) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
for (let letterIndex = 0; letterIndex < input.length; letterIndex++) {
|
|
131
|
+
const letter = input[letterIndex] || '';
|
|
132
|
+
if (!hasCase(letter)) {
|
|
133
|
+
if (options?.blockNoCaseCharacters) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (caseType === StringCaseEnum.Upper && letter !== letter.toUpperCase()) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
else if (caseType === StringCaseEnum.Lower && letter !== letter.toLowerCase()) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
exports.isCase = isCase;
|
|
112
150
|
function camelCaseToKebabCase(rawCamelCase) {
|
|
113
151
|
const kebabCase = rawCamelCase
|
|
114
152
|
.split('')
|
|
115
153
|
.reduce((accum, currentLetter, index, originalString) => {
|
|
116
|
-
const previousLetter = index > 0 ? originalString[index - 1] : '';
|
|
117
|
-
const nextLetter = index < originalString.length - 1 ? originalString[index + 1] : '';
|
|
118
|
-
const possibleWordBoundary =
|
|
154
|
+
const previousLetter = index > 0 ? originalString[index - 1] || '' : '';
|
|
155
|
+
const nextLetter = index < originalString.length - 1 ? originalString[index + 1] || '' : '';
|
|
156
|
+
const possibleWordBoundary = isCase(previousLetter, StringCaseEnum.Lower, { blockNoCaseCharacters: true }) ||
|
|
157
|
+
isCase(nextLetter, StringCaseEnum.Lower, { blockNoCaseCharacters: true });
|
|
119
158
|
if (currentLetter === currentLetter.toLowerCase() ||
|
|
120
159
|
index === 0 ||
|
|
121
160
|
!possibleWordBoundary) {
|
|
@@ -95,17 +95,54 @@ export function kebabCaseToCamelCase(rawKebabCase, casingOptions = defaultCasing
|
|
|
95
95
|
});
|
|
96
96
|
return maybeCapitalize(camelCase, casingOptions);
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
export var StringCaseEnum;
|
|
99
|
+
(function (StringCaseEnum) {
|
|
100
|
+
StringCaseEnum["Upper"] = "upper";
|
|
101
|
+
StringCaseEnum["Lower"] = "lower";
|
|
102
|
+
})(StringCaseEnum || (StringCaseEnum = {}));
|
|
103
|
+
/** Indicates whether the given string has different lower and upper case variants. */
|
|
104
|
+
export function hasCase(input) {
|
|
105
|
+
return input.toLowerCase() !== input.toUpperCase();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Checks if the given string is exclusively of the specific case.
|
|
109
|
+
*
|
|
110
|
+
* Note that some characters have no casing, such as punctuation (they have no difference between
|
|
111
|
+
* upper and lower casings). By default, those letters always return `true` for this function,
|
|
112
|
+
* regardless of which `caseType` is provided. To instead return `false` for any such characters,
|
|
113
|
+
* pass in an options object and set blockNoCaseCharacters to true.
|
|
114
|
+
*/
|
|
115
|
+
export function isCase(input, caseType, options) {
|
|
116
|
+
if (!input && options?.blockNoCaseCharacters) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
for (let letterIndex = 0; letterIndex < input.length; letterIndex++) {
|
|
120
|
+
const letter = input[letterIndex] || '';
|
|
121
|
+
if (!hasCase(letter)) {
|
|
122
|
+
if (options?.blockNoCaseCharacters) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (caseType === StringCaseEnum.Upper && letter !== letter.toUpperCase()) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
else if (caseType === StringCaseEnum.Lower && letter !== letter.toLowerCase()) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
101
137
|
}
|
|
102
138
|
export function camelCaseToKebabCase(rawCamelCase) {
|
|
103
139
|
const kebabCase = rawCamelCase
|
|
104
140
|
.split('')
|
|
105
141
|
.reduce((accum, currentLetter, index, originalString) => {
|
|
106
|
-
const previousLetter = index > 0 ? originalString[index - 1] : '';
|
|
107
|
-
const nextLetter = index < originalString.length - 1 ? originalString[index + 1] : '';
|
|
108
|
-
const possibleWordBoundary =
|
|
142
|
+
const previousLetter = index > 0 ? originalString[index - 1] || '' : '';
|
|
143
|
+
const nextLetter = index < originalString.length - 1 ? originalString[index + 1] || '' : '';
|
|
144
|
+
const possibleWordBoundary = isCase(previousLetter, StringCaseEnum.Lower, { blockNoCaseCharacters: true }) ||
|
|
145
|
+
isCase(nextLetter, StringCaseEnum.Lower, { blockNoCaseCharacters: true });
|
|
109
146
|
if (currentLetter === currentLetter.toLowerCase() ||
|
|
110
147
|
index === 0 ||
|
|
111
148
|
!possibleWordBoundary) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PartialAndUndefined } from './object/object';
|
|
1
2
|
import { AtLeastTuple } from './tuple';
|
|
2
3
|
/**
|
|
3
4
|
* Join elements into a string with commas separating each value. Add a conjunction before the final
|
|
@@ -21,6 +22,28 @@ export type CasingOptions = {
|
|
|
21
22
|
};
|
|
22
23
|
export declare function capitalizeFirstLetter<InputGeneric extends string>(input: InputGeneric): Capitalize<InputGeneric>;
|
|
23
24
|
export declare function kebabCaseToCamelCase(rawKebabCase: string, casingOptions?: Partial<CasingOptions> | undefined): string;
|
|
25
|
+
export declare enum StringCaseEnum {
|
|
26
|
+
Upper = "upper",
|
|
27
|
+
Lower = "lower"
|
|
28
|
+
}
|
|
29
|
+
/** Indicates whether the given string has different lower and upper case variants. */
|
|
30
|
+
export declare function hasCase(input: string): boolean;
|
|
31
|
+
export type IsCaseOptions = {
|
|
32
|
+
/**
|
|
33
|
+
* Block characters that don't have different upper and lower case versions (such as
|
|
34
|
+
* punctuation).
|
|
35
|
+
*/
|
|
36
|
+
blockNoCaseCharacters: boolean;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Checks if the given string is exclusively of the specific case.
|
|
40
|
+
*
|
|
41
|
+
* Note that some characters have no casing, such as punctuation (they have no difference between
|
|
42
|
+
* upper and lower casings). By default, those letters always return `true` for this function,
|
|
43
|
+
* regardless of which `caseType` is provided. To instead return `false` for any such characters,
|
|
44
|
+
* pass in an options object and set blockNoCaseCharacters to true.
|
|
45
|
+
*/
|
|
46
|
+
export declare function isCase(input: string, caseType: StringCaseEnum, options?: PartialAndUndefined<IsCaseOptions>): boolean;
|
|
24
47
|
export declare function camelCaseToKebabCase(rawCamelCase: string): string;
|
|
25
48
|
export declare function replaceStringAtIndex(originalString: string, start: number, newString: string, length?: number): string;
|
|
26
49
|
/**
|