@beauraines/node-helpers 4.2.0 → 4.3.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [4.3.0](https://github.com/beauraines/node-helpers/compare/v4.2.1...v4.3.0) (2024-10-14)
6
+
7
+
8
+ ### Features
9
+
10
+ * string to upper case snake case conversion function ([8cd6f85](https://github.com/beauraines/node-helpers/commit/8cd6f8516d24e8ef19c65508814b4aefd65030e7))
11
+
12
+ ### [4.2.1](https://github.com/beauraines/node-helpers/compare/v4.2.0...v4.2.1) (2024-10-13)
13
+
5
14
  ## [4.2.0](https://github.com/beauraines/node-helpers/compare/v4.1.1...v4.2.0) (2024-10-06)
6
15
 
7
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beauraines/node-helpers",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "description": "Collection of node helpers",
5
5
  "main": "index.js",
6
6
  "repository": {
package/src/helpers.js CHANGED
@@ -16,6 +16,14 @@ function toTitleCase(str) {
16
16
  );
17
17
  }
18
18
 
19
+ const toUpperSnakeCase = (str) => {
20
+ return str
21
+ .replace(/([a-z])([A-Z])/g, '$1_$2') // Add underscore before capital letters
22
+ .replace(/[^a-zA-Z0-9_]/g, '_') // Replace non-alphanumeric characters with underscore
23
+ .toUpperCase(); // Convert to uppercase
24
+ }
25
+
26
+
19
27
  /**
20
28
  * Removes newline characters \r and/or \n from a string
21
29
  * @param {string} string to remove newlines from
@@ -213,6 +221,7 @@ module.exports = {
213
221
  streamToBuffer,
214
222
  stripNewLines,
215
223
  toTitleCase,
224
+ toUpperSnakeCase,
216
225
  unixTimestamp,
217
226
  writeFile
218
227
  }
@@ -30,5 +30,13 @@ describe('helpers',()=> {
30
30
  expect(helper.sparkline(input,label, options)).toBe(expectedOutput)
31
31
  })
32
32
 
33
+ it('should return an upper case snake case string',()=>{
34
+ const expectedOutput = 'NEXT_WEEK';
35
+ const inputs = ['nextWeek','next-week','next_week'];
36
+ inputs.forEach( i => {
37
+ expect(helper.toUpperSnakeCase(i)).toBe(expectedOutput)
38
+ })
39
+ })
40
+
33
41
  })
34
42