@skmtc/core 0.0.828 → 0.0.829

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.
@@ -77,6 +77,8 @@ export declare const decapitalize: (str: string) => string;
77
77
  type CamelCaseOptions = {
78
78
  /** Whether to capitalize the first character (PascalCase) */
79
79
  upperFirst?: boolean;
80
+ /** Whether to retain underscores in place when converting strings */
81
+ retainUnderscores?: boolean;
80
82
  };
81
83
  /**
82
84
  * Converts a string to camelCase, removing non-alphanumeric characters.
@@ -88,6 +90,7 @@ type CamelCaseOptions = {
88
90
  * @param str - The string to convert to camelCase
89
91
  * @param options - Options to control the conversion
90
92
  * @param options.upperFirst - Whether to capitalize the first character (default: false)
93
+ * @param options.retainUnderscores - Whether to retain underscores in place (default: false)
91
94
  * @returns The camelCase version of the input string
92
95
  *
93
96
  * @example Basic usage
@@ -110,7 +113,15 @@ type CamelCaseOptions = {
110
113
  * camelCase('XML_HTTP_Request'); // 'xmlHttpRequest'
111
114
  * camelCase('2fa-enabled'); // '2faEnabled'
112
115
  * ```
116
+ *
117
+ * @example Retaining underscores (retainUnderscores)
118
+ * ```typescript
119
+ * camelCase('user_name', { retainUnderscores: true }); // 'user_name'
120
+ * camelCase('api-key_token', { retainUnderscores: true }); // 'apiKey_token'
121
+ * camelCase('get_user_by_id', { retainUnderscores: true }); // 'get_user_by_id'
122
+ * camelCase('user_profile', { upperFirst: true, retainUnderscores: true }); // 'User_profile'
123
+ * ```
113
124
  */
114
- export declare const camelCase: (str: string, { upperFirst }?: CamelCaseOptions) => string;
125
+ export declare const camelCase: (str: string, { upperFirst, retainUnderscores }?: CamelCaseOptions) => string;
115
126
  export {};
116
127
  //# sourceMappingURL=strings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/helpers/strings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH;;;;;;;;;;;;GAYG;AACH,OAAO,sBAAsB,CAAC;AAE9B,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,MAExC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAE1C,CAAA;AAED;;GAEG;AACH,KAAK,gBAAgB,GAAG;IACtB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,EAAE,iBAAgB,gBAAqB,KAAG,MAgB9E,CAAA"}
1
+ {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/helpers/strings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH;;;;;;;;;;;;GAYG;AACH,OAAO,sBAAsB,CAAC;AAE9B,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,MAExC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAE1C,CAAA;AAED;;GAEG;AACH,KAAK,gBAAgB,GAAG;IACtB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,qEAAqE;IACrE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,EAAE,oCAAmC,gBAAqB,KAAG,MA+BjG,CAAA"}
@@ -85,6 +85,7 @@ export const decapitalize = (str) => {
85
85
  * @param str - The string to convert to camelCase
86
86
  * @param options - Options to control the conversion
87
87
  * @param options.upperFirst - Whether to capitalize the first character (default: false)
88
+ * @param options.retainUnderscores - Whether to retain underscores in place (default: false)
88
89
  * @returns The camelCase version of the input string
89
90
  *
90
91
  * @example Basic usage
@@ -107,16 +108,38 @@ export const decapitalize = (str) => {
107
108
  * camelCase('XML_HTTP_Request'); // 'xmlHttpRequest'
108
109
  * camelCase('2fa-enabled'); // '2faEnabled'
109
110
  * ```
111
+ *
112
+ * @example Retaining underscores (retainUnderscores)
113
+ * ```typescript
114
+ * camelCase('user_name', { retainUnderscores: true }); // 'user_name'
115
+ * camelCase('api-key_token', { retainUnderscores: true }); // 'apiKey_token'
116
+ * camelCase('get_user_by_id', { retainUnderscores: true }); // 'get_user_by_id'
117
+ * camelCase('user_profile', { upperFirst: true, retainUnderscores: true }); // 'User_profile'
118
+ * ```
110
119
  */
111
- export const camelCase = (str, { upperFirst } = {}) => {
112
- let doCapitalize = Boolean(upperFirst);
113
- const camelCased = str.replace(/[^a-zA-Z0-9]+([a-zA-Z0-9]+)/g, (_, matched) => {
114
- if (doCapitalize) {
115
- return capitalize(matched);
120
+ export const camelCase = (str, { upperFirst, retainUnderscores } = {}) => {
121
+ // Check if string starts with a delimiter
122
+ const startsWithDelimiter = retainUnderscores
123
+ ? /^[^a-zA-Z0-9_]/.test(str) // Non-alphanumeric except underscore
124
+ : /^[^a-zA-Z0-9]/.test(str); // Non-alphanumeric including underscore
125
+ let isFirstMatch = true;
126
+ // Determine delimiter pattern based on retainUnderscores
127
+ const delimiterPattern = retainUnderscores
128
+ ? /[^a-zA-Z0-9_]+([a-zA-Z0-9_]+)/g // Treat underscore as regular character
129
+ : /[^a-zA-Z0-9]+([a-zA-Z0-9]+)/g; // Treat underscore as delimiter
130
+ const camelCased = str.replace(delimiterPattern, (_, matched) => {
131
+ // If string starts with delimiter and this is the first match:
132
+ // - Capitalize only if upperFirst is true
133
+ // Otherwise, always capitalize (word comes after delimiter)
134
+ if (isFirstMatch && startsWithDelimiter && !upperFirst) {
135
+ isFirstMatch = false;
136
+ return matched;
116
137
  }
117
- doCapitalize = true;
118
- return matched;
138
+ isFirstMatch = false;
139
+ return capitalize(matched);
119
140
  });
120
- const cleaned = camelCased.replaceAll(/[^a-z0-9]*/gi, '');
141
+ // Clean non-alphanumeric characters (preserving underscores if retainUnderscores)
142
+ const cleanPattern = retainUnderscores ? /[^a-zA-Z0-9_]/g : /[^a-zA-Z0-9]/g;
143
+ const cleaned = camelCased.replace(cleanPattern, '');
121
144
  return upperFirst ? capitalize(cleaned) : cleaned;
122
145
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.828",
3
+ "version": "0.0.829",
4
4
  "description": "Skmtc is a declarative code generation framework",
5
5
  "keywords": [
6
6
  "openapi",
@@ -77,6 +77,8 @@ export declare const decapitalize: (str: string) => string;
77
77
  type CamelCaseOptions = {
78
78
  /** Whether to capitalize the first character (PascalCase) */
79
79
  upperFirst?: boolean;
80
+ /** Whether to retain underscores in place when converting strings */
81
+ retainUnderscores?: boolean;
80
82
  };
81
83
  /**
82
84
  * Converts a string to camelCase, removing non-alphanumeric characters.
@@ -88,6 +90,7 @@ type CamelCaseOptions = {
88
90
  * @param str - The string to convert to camelCase
89
91
  * @param options - Options to control the conversion
90
92
  * @param options.upperFirst - Whether to capitalize the first character (default: false)
93
+ * @param options.retainUnderscores - Whether to retain underscores in place (default: false)
91
94
  * @returns The camelCase version of the input string
92
95
  *
93
96
  * @example Basic usage
@@ -110,7 +113,15 @@ type CamelCaseOptions = {
110
113
  * camelCase('XML_HTTP_Request'); // 'xmlHttpRequest'
111
114
  * camelCase('2fa-enabled'); // '2faEnabled'
112
115
  * ```
116
+ *
117
+ * @example Retaining underscores (retainUnderscores)
118
+ * ```typescript
119
+ * camelCase('user_name', { retainUnderscores: true }); // 'user_name'
120
+ * camelCase('api-key_token', { retainUnderscores: true }); // 'apiKey_token'
121
+ * camelCase('get_user_by_id', { retainUnderscores: true }); // 'get_user_by_id'
122
+ * camelCase('user_profile', { upperFirst: true, retainUnderscores: true }); // 'User_profile'
123
+ * ```
113
124
  */
114
- export declare const camelCase: (str: string, { upperFirst }?: CamelCaseOptions) => string;
125
+ export declare const camelCase: (str: string, { upperFirst, retainUnderscores }?: CamelCaseOptions) => string;
115
126
  export {};
116
127
  //# sourceMappingURL=strings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/helpers/strings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH;;;;;;;;;;;;GAYG;AACH,OAAO,sBAAsB,CAAC;AAE9B,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,MAExC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAE1C,CAAA;AAED;;GAEG;AACH,KAAK,gBAAgB,GAAG;IACtB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,EAAE,iBAAgB,gBAAqB,KAAG,MAgB9E,CAAA"}
1
+ {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/helpers/strings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH;;;;;;;;;;;;GAYG;AACH,OAAO,sBAAsB,CAAC;AAE9B,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,MAExC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAE1C,CAAA;AAED;;GAEG;AACH,KAAK,gBAAgB,GAAG;IACtB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,qEAAqE;IACrE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,EAAE,oCAAmC,gBAAqB,KAAG,MA+BjG,CAAA"}
@@ -90,6 +90,7 @@ exports.decapitalize = decapitalize;
90
90
  * @param str - The string to convert to camelCase
91
91
  * @param options - Options to control the conversion
92
92
  * @param options.upperFirst - Whether to capitalize the first character (default: false)
93
+ * @param options.retainUnderscores - Whether to retain underscores in place (default: false)
93
94
  * @returns The camelCase version of the input string
94
95
  *
95
96
  * @example Basic usage
@@ -112,17 +113,39 @@ exports.decapitalize = decapitalize;
112
113
  * camelCase('XML_HTTP_Request'); // 'xmlHttpRequest'
113
114
  * camelCase('2fa-enabled'); // '2faEnabled'
114
115
  * ```
116
+ *
117
+ * @example Retaining underscores (retainUnderscores)
118
+ * ```typescript
119
+ * camelCase('user_name', { retainUnderscores: true }); // 'user_name'
120
+ * camelCase('api-key_token', { retainUnderscores: true }); // 'apiKey_token'
121
+ * camelCase('get_user_by_id', { retainUnderscores: true }); // 'get_user_by_id'
122
+ * camelCase('user_profile', { upperFirst: true, retainUnderscores: true }); // 'User_profile'
123
+ * ```
115
124
  */
116
- const camelCase = (str, { upperFirst } = {}) => {
117
- let doCapitalize = Boolean(upperFirst);
118
- const camelCased = str.replace(/[^a-zA-Z0-9]+([a-zA-Z0-9]+)/g, (_, matched) => {
119
- if (doCapitalize) {
120
- return (0, exports.capitalize)(matched);
125
+ const camelCase = (str, { upperFirst, retainUnderscores } = {}) => {
126
+ // Check if string starts with a delimiter
127
+ const startsWithDelimiter = retainUnderscores
128
+ ? /^[^a-zA-Z0-9_]/.test(str) // Non-alphanumeric except underscore
129
+ : /^[^a-zA-Z0-9]/.test(str); // Non-alphanumeric including underscore
130
+ let isFirstMatch = true;
131
+ // Determine delimiter pattern based on retainUnderscores
132
+ const delimiterPattern = retainUnderscores
133
+ ? /[^a-zA-Z0-9_]+([a-zA-Z0-9_]+)/g // Treat underscore as regular character
134
+ : /[^a-zA-Z0-9]+([a-zA-Z0-9]+)/g; // Treat underscore as delimiter
135
+ const camelCased = str.replace(delimiterPattern, (_, matched) => {
136
+ // If string starts with delimiter and this is the first match:
137
+ // - Capitalize only if upperFirst is true
138
+ // Otherwise, always capitalize (word comes after delimiter)
139
+ if (isFirstMatch && startsWithDelimiter && !upperFirst) {
140
+ isFirstMatch = false;
141
+ return matched;
121
142
  }
122
- doCapitalize = true;
123
- return matched;
143
+ isFirstMatch = false;
144
+ return (0, exports.capitalize)(matched);
124
145
  });
125
- const cleaned = camelCased.replaceAll(/[^a-z0-9]*/gi, '');
146
+ // Clean non-alphanumeric characters (preserving underscores if retainUnderscores)
147
+ const cleanPattern = retainUnderscores ? /[^a-zA-Z0-9_]/g : /[^a-zA-Z0-9]/g;
148
+ const cleaned = camelCased.replace(cleanPattern, '');
126
149
  return upperFirst ? (0, exports.capitalize)(cleaned) : cleaned;
127
150
  };
128
151
  exports.camelCase = camelCase;