entropic-bond 1.16.0 → 1.17.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.
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface Values {
|
|
2
|
+
[varName: string]: string;
|
|
3
|
+
}
|
|
4
|
+
export declare function replaceValue(text: string, values: Values): string;
|
|
5
|
+
export declare function camelCase(str: string): string;
|
|
6
|
+
export declare function snakeCase(str: string, snakeChar?: string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.snakeCase = exports.camelCase = exports.replaceValue = void 0;
|
|
4
|
+
function replaceValue(text, values) {
|
|
5
|
+
if (!text)
|
|
6
|
+
return '';
|
|
7
|
+
return text.replace(/\${\s*(\w*)\s*}/g, function (_match, group) {
|
|
8
|
+
return values[group] || '';
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
exports.replaceValue = replaceValue;
|
|
12
|
+
function camelCase(str) {
|
|
13
|
+
if (!str)
|
|
14
|
+
return '';
|
|
15
|
+
return str.replace(/([-_][\w])/g, function (group) { return group.toUpperCase().replace('-', '').replace('_', ''); });
|
|
16
|
+
}
|
|
17
|
+
exports.camelCase = camelCase;
|
|
18
|
+
function snakeCase(str, snakeChar) {
|
|
19
|
+
if (snakeChar === void 0) { snakeChar = '-'; }
|
|
20
|
+
if (!str)
|
|
21
|
+
return '';
|
|
22
|
+
return str[0].toLocaleLowerCase() + str.slice(1).replace(/([A-Z])/g, function (g) { return snakeChar + g[0].toLowerCase(); });
|
|
23
|
+
}
|
|
24
|
+
exports.snakeCase = snakeCase;
|
|
25
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;AAIA,SAAgB,YAAY,CAAE,IAAY,EAAE,MAAc;IACzD,IAAK,CAAC,IAAI;QAAG,OAAO,EAAE,CAAA;IAEtB,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,UAAU,MAAM,EAAG,KAAK;QAC/D,OAAO,MAAM,CAAE,KAAK,CAAE,IAAI,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;AACJ,CAAC;AAND,oCAMC;AAED,SAAgB,SAAS,CAAE,GAAW;IACrC,IAAK,CAAC,GAAG;QAAG,OAAO,EAAE,CAAA;IAErB,OAAO,GAAG,CAAC,OAAO,CACjB,aAAa,EACb,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,EAArD,CAAqD,CAC9D,CAAA;AACF,CAAC;AAPD,8BAOC;AAED,SAAgB,SAAS,CAAE,GAAW,EAAE,SAAuB;IAAvB,0BAAA,EAAA,eAAuB;IAC9D,IAAK,CAAC,GAAG;QAAG,OAAO,EAAE,CAAA;IACrB,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,UAAA,CAAC,IAAI,OAAA,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAA9B,CAA8B,CAAE,CAAC;AAC5G,CAAC;AAHD,8BAGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var utils_1 = require("./utils");
|
|
4
|
+
describe('Utils', function () {
|
|
5
|
+
describe('replaceValues', function () {
|
|
6
|
+
var text = 'The population of ${country} is ${ people} million \
|
|
7
|
+
and the GDP is $${ gdpValue } million';
|
|
8
|
+
var expected = 'The population of U.S.A. is 100 million \
|
|
9
|
+
and the GDP is $1000 million';
|
|
10
|
+
var vars = {
|
|
11
|
+
country: 'U.S.A.',
|
|
12
|
+
people: '100',
|
|
13
|
+
gdpValue: '1000'
|
|
14
|
+
};
|
|
15
|
+
it('should replace vars as a template literal', function () {
|
|
16
|
+
expect(utils_1.replaceValue(text, vars)).toEqual(expected);
|
|
17
|
+
});
|
|
18
|
+
it('should replace vars with empty value', function () {
|
|
19
|
+
vars.country = '';
|
|
20
|
+
vars.people = undefined;
|
|
21
|
+
expect(utils_1.replaceValue('The population of ${country} is ${ people} million', vars)).toEqual('The population of is million');
|
|
22
|
+
});
|
|
23
|
+
it('should resturn empty string on falsy', function () {
|
|
24
|
+
expect(utils_1.replaceValue(undefined, vars)).toEqual('');
|
|
25
|
+
expect(utils_1.replaceValue(null, vars)).toEqual('');
|
|
26
|
+
expect(utils_1.replaceValue('', vars)).toEqual('');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe('Camel/Snake case', function () {
|
|
30
|
+
it('should convert to camel case', function () {
|
|
31
|
+
expect(utils_1.camelCase('snake_case')).toEqual('snakeCase');
|
|
32
|
+
expect(utils_1.camelCase('snake-case')).toEqual('snakeCase');
|
|
33
|
+
expect(utils_1.camelCase('snake-Case')).toEqual('snakeCase');
|
|
34
|
+
expect(utils_1.camelCase('snake_Case')).toEqual('snakeCase');
|
|
35
|
+
expect(utils_1.camelCase('Snake-Case')).toEqual('SnakeCase');
|
|
36
|
+
expect(utils_1.camelCase('Snake_Case')).toEqual('SnakeCase');
|
|
37
|
+
});
|
|
38
|
+
it('should return empty string on invalid original string for camel case', function () {
|
|
39
|
+
expect(utils_1.camelCase(undefined)).toEqual('');
|
|
40
|
+
expect(utils_1.camelCase(null)).toEqual('');
|
|
41
|
+
expect(utils_1.camelCase('')).toEqual('');
|
|
42
|
+
});
|
|
43
|
+
it('should convert to snake case', function () {
|
|
44
|
+
expect(utils_1.snakeCase('snakeCase')).toEqual('snake-case');
|
|
45
|
+
expect(utils_1.snakeCase('snakeCase', '_')).toEqual('snake_case');
|
|
46
|
+
expect(utils_1.snakeCase('SnakeCase')).toEqual('snake-case');
|
|
47
|
+
expect(utils_1.snakeCase('SnakeCase', '_')).toEqual('snake_case');
|
|
48
|
+
});
|
|
49
|
+
it('should return empty string on invalid original string for snake case', function () {
|
|
50
|
+
expect(utils_1.snakeCase(undefined)).toEqual('');
|
|
51
|
+
expect(utils_1.snakeCase(null)).toEqual('');
|
|
52
|
+
expect(utils_1.snakeCase('')).toEqual('');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=utils.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.spec.js","sourceRoot":"","sources":["../../src/utils/utils.spec.ts"],"names":[],"mappings":";;AAAA,iCAA4D;AAE5D,QAAQ,CAAE,OAAO,EAAE;IAClB,QAAQ,CAAE,eAAe,EAAE;QAC1B,IAAM,IAAI,GAAG;iDACkC,CAAA;QAC/C,IAAM,QAAQ,GAAG;wCACqB,CAAA;QACtC,IAAM,IAAI,GAAG;YACZ,OAAO,EAAE,QAAQ;YACjB,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,MAAM;SAChB,CAAA;QAED,EAAE,CAAE,2CAA2C,EAAE;YAChD,MAAM,CAAE,oBAAY,CAAE,IAAI,EAAE,IAAI,CAAE,CAAE,CAAC,OAAO,CAAE,QAAQ,CAAE,CAAA;QACzD,CAAC,CAAC,CAAA;QAEF,EAAE,CAAE,sCAAsC,EAAE;YAC3C,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;YACjB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;YAEvB,MAAM,CACL,oBAAY,CACX,oDAAoD,EACpD,IAAI,CACJ,CACD,CAAC,OAAO,CAAE,gCAAgC,CAAE,CAAA;QAC9C,CAAC,CAAC,CAAA;QAEF,EAAE,CAAE,sCAAsC,EAAE;YAC3C,MAAM,CAA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