@elliemae/ds-props-helpers 2.2.0-alpha.5 → 2.2.0-next.3
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/cjs/defaultProps/index.js +9 -28
- package/cjs/defaultProps/useMemoMergePropsWithDefault.js +44 -44
- package/cjs/getProps/index.js +20 -37
- package/cjs/globalProps/constants.js +15 -0
- package/cjs/globalProps/globalAttributesPropTypes.js +372 -0
- package/cjs/globalProps/index.js +11 -0
- package/cjs/globalProps/useGetGlobalAttributes.js +36 -0
- package/cjs/index.js +24 -30
- package/cjs/validation/errorTemplates.js +12 -44
- package/cjs/validation/index.js +15 -30
- package/cjs/validation/typescriptGuards.js +31 -60
- package/cjs/validation/typescriptParsers.js +34 -65
- package/cjs/validation/typescriptValidator.js +135 -99
- package/cjs/validation/validator.js +24 -43
- package/esm/defaultProps/index.js +1 -3
- package/esm/defaultProps/useMemoMergePropsWithDefault.js +34 -14
- package/esm/getProps/index.js +15 -8
- package/esm/globalProps/constants.js +11 -0
- package/esm/globalProps/globalAttributesPropTypes.js +368 -0
- package/esm/globalProps/index.js +2 -0
- package/esm/globalProps/useGetGlobalAttributes.js +32 -0
- package/esm/index.js +7 -5
- package/esm/validation/errorTemplates.js +7 -15
- package/esm/validation/index.js +3 -5
- package/esm/validation/typescriptGuards.js +18 -31
- package/esm/validation/typescriptParsers.js +30 -36
- package/esm/validation/typescriptValidator.js +106 -57
- package/esm/validation/validator.js +18 -12
- package/package.json +17 -1
- package/types/globalProps/constants.d.ts +3 -0
- package/types/globalProps/globalAttributesPropTypes.d.ts +2169 -0
- package/types/globalProps/index.d.ts +2 -0
- package/types/globalProps/useGetGlobalAttributes.d.ts +5 -0
- package/types/index.d.ts +1 -0
- package/types/validation/typescriptValidator.d.ts +2 -2
- package/cjs/defaultProps/index.js.map +0 -7
- package/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +0 -7
- package/cjs/getProps/index.js.map +0 -7
- package/cjs/index.js.map +0 -7
- package/cjs/tests/test.schema.js +0 -67
- package/cjs/tests/test.schema.js.map +0 -7
- package/cjs/validation/errorTemplates.js.map +0 -7
- package/cjs/validation/index.js.map +0 -7
- package/cjs/validation/typescriptGuards.js.map +0 -7
- package/cjs/validation/typescriptParsers.js.map +0 -7
- package/cjs/validation/typescriptValidator.js.map +0 -7
- package/cjs/validation/validator.js.map +0 -7
- package/esm/defaultProps/index.js.map +0 -7
- package/esm/defaultProps/useMemoMergePropsWithDefault.js.map +0 -7
- package/esm/getProps/index.js.map +0 -7
- package/esm/index.js.map +0 -7
- package/esm/tests/test.schema.js +0 -38
- package/esm/tests/test.schema.js.map +0 -7
- package/esm/validation/errorTemplates.js.map +0 -7
- package/esm/validation/index.js.map +0 -7
- package/esm/validation/typescriptGuards.js.map +0 -7
- package/esm/validation/typescriptParsers.js.map +0 -7
- package/esm/validation/typescriptValidator.js.map +0 -7
- package/esm/validation/validator.js.map +0 -7
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
9
|
+
var react = require('react');
|
|
10
|
+
var constants = require('./constants.js');
|
|
11
|
+
|
|
12
|
+
const useGetGlobalAttributes = (props, overrides) => {
|
|
13
|
+
const componentGlobalAttributes = react.useMemo(() => {
|
|
14
|
+
const globalAttributesObject = {};
|
|
15
|
+
Object.entries(props).forEach(_ref => {
|
|
16
|
+
let [key, value] = _ref;
|
|
17
|
+
|
|
18
|
+
if (key in constants.globalAttributes || key.startsWith('data-')) {
|
|
19
|
+
if (key in overrides && typeof value === 'function' && typeof overrides[key] === 'function') {
|
|
20
|
+
const newFunc = function () {
|
|
21
|
+
value(...arguments);
|
|
22
|
+
overrides[key](...arguments);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
globalAttributesObject[key] = newFunc;
|
|
26
|
+
} else {
|
|
27
|
+
globalAttributesObject[key] = value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return globalAttributesObject;
|
|
32
|
+
}, [props, overrides]);
|
|
33
|
+
return componentGlobalAttributes;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.useGetGlobalAttributes = useGetGlobalAttributes;
|
package/cjs/index.js
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var React = __toESM(require("react"));
|
|
26
|
-
__reExport(src_exports, require("./defaultProps"));
|
|
27
|
-
__reExport(src_exports, require("./validation"));
|
|
28
|
-
__reExport(src_exports, require("./getProps"));
|
|
29
|
-
module.exports = __toCommonJS(src_exports);
|
|
30
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var useMemoMergePropsWithDefault = require('./defaultProps/useMemoMergePropsWithDefault.js');
|
|
6
|
+
var validator = require('./validation/validator.js');
|
|
7
|
+
var errorTemplates = require('./validation/errorTemplates.js');
|
|
8
|
+
var typescriptValidator = require('./validation/typescriptValidator.js');
|
|
9
|
+
var index = require('./getProps/index.js');
|
|
10
|
+
var useGetGlobalAttributes = require('./globalProps/useGetGlobalAttributes.js');
|
|
11
|
+
var globalAttributesPropTypes = require('./globalProps/globalAttributesPropTypes.js');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.useMemoMergePropsWithDefault = useMemoMergePropsWithDefault.useMemoMergePropsWithDefault;
|
|
16
|
+
exports.useValidatePropTypes = validator.useValidatePropTypes;
|
|
17
|
+
exports.throwRequiredError = errorTemplates.throwRequiredError;
|
|
18
|
+
exports.throwTypeError = errorTemplates.throwTypeError;
|
|
19
|
+
exports.useValidateTypescriptPropTypes = typescriptValidator.useValidateTypescriptPropTypes;
|
|
20
|
+
exports.validateTypescriptPropTypesImplementation = typescriptValidator.validateTypescriptPropTypesImplementation;
|
|
21
|
+
exports.getAriaProps = index.getAriaProps;
|
|
22
|
+
exports.getDataProps = index.getDataProps;
|
|
23
|
+
exports.useGetGlobalAttributes = useGetGlobalAttributes.useGetGlobalAttributes;
|
|
24
|
+
exports.globalAttributesPropTypes = globalAttributesPropTypes.globalAttributesPropTypes;
|
|
@@ -1,48 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(module2))
|
|
15
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (module2, isNodeMode) => {
|
|
21
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
-
};
|
|
23
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
-
return (module2, temp) => {
|
|
25
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
-
};
|
|
27
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
-
var errorTemplates_exports = {};
|
|
29
|
-
__export(errorTemplates_exports, {
|
|
30
|
-
throwRequiredError: () => throwRequiredError,
|
|
31
|
-
throwTypeError: () => throwTypeError
|
|
32
|
-
});
|
|
33
|
-
var React = __toESM(require("react"));
|
|
34
|
-
const throwTypeError = (componentName, validPropKey, invalidProp, validFormat) => {
|
|
35
|
-
throw new Error(`${componentName}:: You are trying to pass a not valid "${validPropKey}" property,
|
|
36
|
-
please provide a valid type.
|
|
1
|
+
'use strict';
|
|
37
2
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/es.string.replace.js');
|
|
6
|
+
|
|
7
|
+
/* eslint-disable max-params */
|
|
8
|
+
const throwTypeError = (componentName, validPropKey, invalidProp, validFormat) => {
|
|
9
|
+
throw new Error("".concat(componentName, ":: You are trying to pass a not valid \"").concat(validPropKey, "\" property, \n please provide a valid type.\n\n Received: ").concat(invalidProp, " (").concat(typeof invalidProp, ")\n Expected: (").concat(validFormat.replace('\n', ' or '), ")\n "));
|
|
41
10
|
};
|
|
42
11
|
const throwRequiredError = (componentName, validPropKey) => {
|
|
43
|
-
throw new Error(
|
|
44
|
-
This property is required.
|
|
45
|
-
`);
|
|
12
|
+
throw new Error("".concat(componentName, ":: Please provide a/an \"").concat(validPropKey, "\" property to use this component. \n This property is required.\n "));
|
|
46
13
|
};
|
|
47
|
-
|
|
48
|
-
|
|
14
|
+
|
|
15
|
+
exports.throwRequiredError = throwRequiredError;
|
|
16
|
+
exports.throwTypeError = throwTypeError;
|
package/cjs/validation/index.js
CHANGED
|
@@ -1,30 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var __toESM = (module2, isNodeMode) => {
|
|
17
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
20
|
-
return (module2, temp) => {
|
|
21
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
22
|
-
};
|
|
23
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
24
|
-
var validation_exports = {};
|
|
25
|
-
var React = __toESM(require("react"));
|
|
26
|
-
__reExport(validation_exports, require("./validator"));
|
|
27
|
-
__reExport(validation_exports, require("./errorTemplates"));
|
|
28
|
-
__reExport(validation_exports, require("./typescriptValidator"));
|
|
29
|
-
module.exports = __toCommonJS(validation_exports);
|
|
30
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var validator = require('./validator.js');
|
|
6
|
+
var errorTemplates = require('./errorTemplates.js');
|
|
7
|
+
var typescriptValidator = require('./typescriptValidator.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.useValidatePropTypes = validator.useValidatePropTypes;
|
|
12
|
+
exports.throwRequiredError = errorTemplates.throwRequiredError;
|
|
13
|
+
exports.throwTypeError = errorTemplates.throwTypeError;
|
|
14
|
+
exports.useValidateTypescriptPropTypes = typescriptValidator.useValidateTypescriptPropTypes;
|
|
15
|
+
exports.validateTypescriptPropTypesImplementation = typescriptValidator.validateTypescriptPropTypesImplementation;
|
|
@@ -1,65 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(module2))
|
|
15
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (module2, isNodeMode) => {
|
|
21
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
-
};
|
|
23
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
-
return (module2, temp) => {
|
|
25
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
-
};
|
|
27
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
-
var typescriptGuards_exports = {};
|
|
29
|
-
__export(typescriptGuards_exports, {
|
|
30
|
-
isArray: () => isArray,
|
|
31
|
-
isFunction: () => isFunction,
|
|
32
|
-
isJSXorNode: () => isJSXorNode,
|
|
33
|
-
isNull: () => isNull,
|
|
34
|
-
isObject: () => isObject,
|
|
35
|
-
isPrimitiveType: () => isPrimitiveType,
|
|
36
|
-
isSomethingWithParenthesis: () => isSomethingWithParenthesis,
|
|
37
|
-
isString: () => isString,
|
|
38
|
-
isUndefined: () => isUndefined,
|
|
39
|
-
isUnion: () => isUnion
|
|
40
|
-
});
|
|
41
|
-
var React = __toESM(require("react"));
|
|
42
|
-
const isPrimitiveType = (format) => ["string", "number", "boolean"].includes(format);
|
|
43
|
-
const isUndefined = (format) => format === '"undefined"';
|
|
44
|
-
const isNull = (format) => format === '"null"';
|
|
45
|
-
const isUnion = (format) => {
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
|
|
9
|
+
const isPrimitiveType = format => ['string', 'number', 'boolean'].includes(format);
|
|
10
|
+
const isUndefined = format => format === '"undefined"';
|
|
11
|
+
const isNull = format => format === '"null"';
|
|
12
|
+
const isUnion = format => {
|
|
46
13
|
let depth = 0;
|
|
47
14
|
let satisfies = false;
|
|
48
|
-
format.split(
|
|
49
|
-
if ([
|
|
50
|
-
depth += 1;
|
|
51
|
-
else if (["}", ")"].includes(char))
|
|
52
|
-
depth -= 1;
|
|
53
|
-
else if (char === "|" && depth === 0)
|
|
54
|
-
satisfies = true;
|
|
15
|
+
format.split('').forEach(char => {
|
|
16
|
+
if (['{', '('].includes(char)) depth += 1;else if (['}', ')'].includes(char)) depth -= 1;else if (char === '|' && depth === 0) satisfies = true;
|
|
55
17
|
});
|
|
56
18
|
return satisfies;
|
|
57
19
|
};
|
|
58
|
-
const isString =
|
|
59
|
-
const isArray =
|
|
60
|
-
const isObject =
|
|
61
|
-
const isFunction =
|
|
62
|
-
const isJSXorNode =
|
|
63
|
-
const isSomethingWithParenthesis =
|
|
64
|
-
|
|
65
|
-
|
|
20
|
+
const isString = format => !isUnion(format) && format[0] === '"' && format.slice(-1) === '"';
|
|
21
|
+
const isArray = format => !isUnion(format) && format.slice(-2) === '[]';
|
|
22
|
+
const isObject = format => format === 'object' || !isUnion(format) && format[0] === '{' && format.slice(-1) === '}';
|
|
23
|
+
const isFunction = format => !isUnion(format) && format === '((...args: any[]) => any)';
|
|
24
|
+
const isJSXorNode = format => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);
|
|
25
|
+
const isSomethingWithParenthesis = format => !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';
|
|
26
|
+
|
|
27
|
+
exports.isArray = isArray;
|
|
28
|
+
exports.isFunction = isFunction;
|
|
29
|
+
exports.isJSXorNode = isJSXorNode;
|
|
30
|
+
exports.isNull = isNull;
|
|
31
|
+
exports.isObject = isObject;
|
|
32
|
+
exports.isPrimitiveType = isPrimitiveType;
|
|
33
|
+
exports.isSomethingWithParenthesis = isSomethingWithParenthesis;
|
|
34
|
+
exports.isString = isString;
|
|
35
|
+
exports.isUndefined = isUndefined;
|
|
36
|
+
exports.isUnion = isUnion;
|
|
@@ -1,76 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (module2, isNodeMode) => {
|
|
21
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
-
};
|
|
23
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
-
return (module2, temp) => {
|
|
25
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
-
};
|
|
27
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
-
var typescriptParsers_exports = {};
|
|
29
|
-
__export(typescriptParsers_exports, {
|
|
30
|
-
typescriptObjectParser: () => typescriptObjectParser
|
|
31
|
-
});
|
|
32
|
-
var React = __toESM(require("react"));
|
|
33
|
-
const typescriptObjectParser = (format) => {
|
|
34
|
-
const keyValuePairs = [];
|
|
35
|
-
let lastKey = "";
|
|
36
|
-
let lastValue = "";
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
|
|
9
|
+
/* eslint-disable complexity */
|
|
10
|
+
const typescriptObjectParser = format => {
|
|
11
|
+
const keyValuePairs = []; // State of the algorithm
|
|
12
|
+
|
|
13
|
+
let lastKey = '';
|
|
14
|
+
let lastValue = '';
|
|
37
15
|
let shouldAppendToKey = true;
|
|
16
|
+
|
|
38
17
|
const pushPair = () => {
|
|
39
|
-
if (lastKey)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
lastValue = "";
|
|
18
|
+
if (lastKey) keyValuePairs.push([lastKey, lastValue]);
|
|
19
|
+
lastKey = '';
|
|
20
|
+
lastValue = '';
|
|
43
21
|
shouldAppendToKey = true;
|
|
44
|
-
};
|
|
22
|
+
}; // Complex -- but working -- logic
|
|
23
|
+
|
|
24
|
+
|
|
45
25
|
let depth = 0;
|
|
46
|
-
format.split(
|
|
47
|
-
if (char ===
|
|
26
|
+
format.split('').forEach(char => {
|
|
27
|
+
if (char === '{') {
|
|
48
28
|
depth += 1;
|
|
49
|
-
if (depth > 1)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (depth > 1)
|
|
53
|
-
lastValue += char;
|
|
29
|
+
if (depth > 1) lastValue += char;
|
|
30
|
+
} else if (char === '}') {
|
|
31
|
+
if (depth > 1) lastValue += char;
|
|
54
32
|
depth -= 1;
|
|
55
|
-
if (depth === 1)
|
|
56
|
-
|
|
57
|
-
} else if (char === ":") {
|
|
33
|
+
if (depth === 1) pushPair();
|
|
34
|
+
} else if (char === ':') {
|
|
58
35
|
shouldAppendToKey = false;
|
|
59
|
-
if (depth > 1)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
pushPair();
|
|
64
|
-
else
|
|
65
|
-
lastValue += char;
|
|
66
|
-
} else if (char === " ") {
|
|
67
|
-
} else if (shouldAppendToKey)
|
|
68
|
-
lastKey += char;
|
|
69
|
-
else
|
|
70
|
-
lastValue += char;
|
|
36
|
+
if (depth > 1) lastValue += char;
|
|
37
|
+
} else if (char === ',') {
|
|
38
|
+
if (depth === 1) pushPair();else lastValue += char;
|
|
39
|
+
} else if (char === ' ') ; else if (shouldAppendToKey) lastKey += char;else lastValue += char;
|
|
71
40
|
});
|
|
72
41
|
pushPair();
|
|
73
42
|
return keyValuePairs;
|
|
74
43
|
};
|
|
75
|
-
|
|
76
|
-
|
|
44
|
+
|
|
45
|
+
exports.typescriptObjectParser = typescriptObjectParser;
|