@lowdefy/operators-change-case 4.0.0-alpha.29 → 4.0.0-alpha.31

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.
@@ -0,0 +1,130 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ /* eslint-disable import/namespace */ import { camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
16
+ import { get, type } from '@lowdefy/helpers';
17
+ import { runClass } from '@lowdefy/operators';
18
+ const changeCase = {
19
+ camelCase,
20
+ capitalCase,
21
+ constantCase,
22
+ dotCase,
23
+ headerCase,
24
+ noCase,
25
+ paramCase,
26
+ pascalCase,
27
+ pathCase,
28
+ sentenceCase,
29
+ snakeCase
30
+ };
31
+ const prepRegex = (prop, location)=>{
32
+ const regex = type.isString(prop) ? {
33
+ pattern: prop
34
+ } : prop;
35
+ if (!type.isObject(regex)) {
36
+ throw new Error(`Operator Error: regex must be string or an object. Received ${JSON.stringify(prop)} at ${location}.`);
37
+ }
38
+ try {
39
+ return new RegExp(regex.pattern, regex.flags || 'gm');
40
+ } catch (e) {
41
+ throw new Error(`Operator Error: ${e.message}. Received: ${JSON.stringify(prop)} at ${location}.`);
42
+ }
43
+ };
44
+ const prep = (args, { location })=>{
45
+ const options = args[1];
46
+ if (!type.isNone(options) && !type.isObject(options)) {
47
+ throw new Error(`Operator Error: options must be an object. Received ${JSON.stringify(options)} at ${location}.`);
48
+ }
49
+ if (type.isObject(options)) {
50
+ if (options.splitRegexp) {
51
+ options.splitRegexp = prepRegex(options.splitRegexp, location);
52
+ }
53
+ if (options.stripRegexp) {
54
+ options.stripRegexp = prepRegex(options.stripRegexp, location);
55
+ }
56
+ }
57
+ return args;
58
+ };
59
+ const convertArray = ({ methodName , on , options })=>{
60
+ return on.map((item)=>{
61
+ if (type.isString(item)) {
62
+ return changeCase[methodName](item, options);
63
+ }
64
+ return item;
65
+ });
66
+ };
67
+ const convertObject = ({ methodName , on , options })=>{
68
+ const result = {};
69
+ const keyConverter = get(options, 'convertKeys') ? (key)=>changeCase[methodName](key, options) : (key)=>key;
70
+ const valueConverter = get(options, 'convertValues', {
71
+ default: true
72
+ }) ? (val)=>changeCase[methodName](val, options) : (val)=>val;
73
+ Object.entries(on).forEach(([key, value])=>{
74
+ if (type.isString(value)) {
75
+ result[keyConverter(key)] = valueConverter(value);
76
+ } else {
77
+ result[keyConverter(key)] = value;
78
+ }
79
+ });
80
+ return result;
81
+ };
82
+ const makeCaseChanger = ({ methodName })=>(on, options = {})=>{
83
+ if (type.isString(on)) {
84
+ return changeCase[methodName](on, options);
85
+ }
86
+ if (type.isArray(on)) {
87
+ return convertArray({
88
+ methodName,
89
+ on,
90
+ options
91
+ });
92
+ }
93
+ if (type.isObject(on)) {
94
+ return convertObject({
95
+ methodName,
96
+ on,
97
+ options
98
+ });
99
+ }
100
+ return on;
101
+ };
102
+ const functions = {};
103
+ const meta = {};
104
+ Object.keys(changeCase).forEach((methodName)=>{
105
+ functions[methodName] = makeCaseChanger({
106
+ methodName
107
+ });
108
+ meta[methodName] = {
109
+ namedArgs: [
110
+ 'on',
111
+ 'options'
112
+ ],
113
+ validTypes: [
114
+ 'array',
115
+ 'object'
116
+ ],
117
+ prep
118
+ };
119
+ });
120
+ function change_case({ params , location , methodName }) {
121
+ return runClass({
122
+ functions,
123
+ location,
124
+ meta,
125
+ methodName,
126
+ operator: '_change_case',
127
+ params
128
+ });
129
+ }
130
+ export default change_case;
@@ -0,0 +1,15 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export { default as _change_case } from './operators/shared/change_case.js';
@@ -0,0 +1,15 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export { default as _change_case } from './operators/shared/change_case.js';
package/dist/types.js ADDED
@@ -0,0 +1,22 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import * as client from './operatorsClient.js';
16
+ import * as server from './operatorsServer.js';
17
+ export default {
18
+ operators: {
19
+ client: Object.keys(client),
20
+ server: Object.keys(server)
21
+ }
22
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/operators-change-case",
3
- "version": "4.0.0-alpha.29",
3
+ "version": "4.0.0-alpha.31",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -42,8 +42,8 @@
42
42
  "test": "jest --coverage"
43
43
  },
44
44
  "dependencies": {
45
- "@lowdefy/helpers": "4.0.0-alpha.29",
46
- "@lowdefy/operators": "4.0.0-alpha.29",
45
+ "@lowdefy/helpers": "4.0.0-alpha.31",
46
+ "@lowdefy/operators": "4.0.0-alpha.31",
47
47
  "change-case": "4.1.2"
48
48
  },
49
49
  "devDependencies": {
@@ -56,5 +56,5 @@
56
56
  "publishConfig": {
57
57
  "access": "public"
58
58
  },
59
- "gitHead": "621a191ebc0a1569ee6669dc74c12f8be5a8c7f3"
59
+ "gitHead": "96ef86d4ce4849f8f11110662efbbaede1bcd5a5"
60
60
  }