@vbarbarosh/node-helpers 3.61.0 → 3.62.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.61.0",
5
+ "version": "3.62.0",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -0,0 +1,9 @@
1
+ function camel_to_snake(s)
2
+ {
3
+ return s
4
+ .replace(/([a-z0-9])([A-Z])/g, '$1_$2') // Insert underscore between lowercase/number and uppercase
5
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') // Separate acronyms from regular CamelCase words
6
+ .toLowerCase();
7
+ }
8
+
9
+ module.exports = camel_to_snake;
@@ -0,0 +1,17 @@
1
+ const assert = require('assert');
2
+ const camel_to_snake = require('./camel_to_snake');
3
+
4
+ const items = [
5
+ ['UPC', 'upc'],
6
+ ['CamelCase', 'camel_case'],
7
+ ['SomeUPCCode', 'some_upc_code'],
8
+ ['XMLHTTPRequest', 'xmlhttp_request'],
9
+ ];
10
+
11
+ describe('camel_to_snake', function () {
12
+ items.forEach(function ([input, expected],) {
13
+ it(`${input === '' ? '☒' : input} → ${expected}`, function () {
14
+ assert.deepStrictEqual(camel_to_snake(input), expected);
15
+ });
16
+ });
17
+ });
@@ -1,8 +1,9 @@
1
+ const camel_to_snake = require('./camel_to_snake');
1
2
  const sanitize_dash_name = require('./sanitize_dash_name');
2
3
 
3
4
  function sanitize_var_name(var_name)
4
5
  {
5
- const out = sanitize_dash_name(var_name).replace(/[^a-z0-9]+/g, '_');
6
+ const out = sanitize_dash_name(camel_to_snake(var_name)).replace(/[^a-z0-9]+/g, '_');
6
7
  if (out.length === 0) {
7
8
  return '_';
8
9
  }
@@ -11,6 +11,16 @@ const items = [
11
11
  ['Ópera Prima', 'opera_prima'],
12
12
  ['1000-stories', '_1000_stories'],
13
13
  ['A, C, D', 'a_c_d'],
14
+ ['@odata.etag', 'odata_etag'],
15
+ ['ItemInternalId', 'item_internal_id'],
16
+ ['UPC', 'upc'],
17
+ ['Sale_price', 'sale_price'],
18
+ ['% de disponibilidad de tiendas', 'de_disponibilidad_de_tiendas'],
19
+ ['%Tiendas con precio moda', 'tiendas_con_precio_moda'],
20
+
21
+ // https://github.com/Advanon/sanitize-s3-objectkey
22
+ // https://github.com/hamxabaig/s3-filename
23
+ // ['some 漢字 ćööł % #fíłéñàmé.jpg', 'some_cool_filename_jpg'],
14
24
  ];
15
25
 
16
26
  describe('sanitize_var_name', function () {