@prismatic-io/spectral 7.2.0 → 7.2.1
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/dist/util.d.ts +14 -3
- package/dist/util.js +25 -5
- package/package.json +1 -1
package/dist/util.d.ts
CHANGED
|
@@ -7,13 +7,23 @@ import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap, JSONForm, C
|
|
|
7
7
|
/**
|
|
8
8
|
* This function returns a lower cased version of the headers passed to it.
|
|
9
9
|
*
|
|
10
|
-
* - `lowerCaseHeaders({"Content-Type": "Application/JSON"}) will return {"content-type": "Application/JSON"}`
|
|
11
|
-
* - `lowerCaseHeaders({"Cache-Control": "max-age=604800"}) will return {"cache-control": "max-age=604800"}`
|
|
12
|
-
* - `lowerCaseHeaders({"Accept-Language": "en-us"}) will return {"accept-language": "en-us"}`
|
|
10
|
+
* - `lowerCaseHeaders({"Content-Type": "Application/JSON"})` will return `{"content-type": "Application/JSON"}`
|
|
11
|
+
* - `lowerCaseHeaders({"Cache-Control": "max-age=604800"})` will return `{"cache-control": "max-age=604800"}`
|
|
12
|
+
* - `lowerCaseHeaders({"Accept-Language": "en-us"})` will return `{"accept-language": "en-us"}`
|
|
13
13
|
* @param headers The headers to convert to lower case
|
|
14
14
|
* @returns This function returns a header object
|
|
15
15
|
* */
|
|
16
16
|
export declare const lowerCaseHeaders: (headers: Record<string, string>) => Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* This function parses a JSON string (if JSON) and returns an object, or returns the object.
|
|
19
|
+
*
|
|
20
|
+
* - `toObject('{"foo":"bar","baz":123}')` will return object `{foo: "bar", baz: 123}`
|
|
21
|
+
* - `toObject({foo:"bar",baz:123})` will return object `{foo: "bar", baz: 123}`
|
|
22
|
+
*
|
|
23
|
+
* @param value The JSON string or object to convert
|
|
24
|
+
* @returns This function returns an object, parsing JSON as necessary
|
|
25
|
+
*/
|
|
26
|
+
export declare const toObject: (value: unknown) => object;
|
|
17
27
|
declare const _default: {
|
|
18
28
|
types: {
|
|
19
29
|
isBool: (value: unknown) => value is boolean;
|
|
@@ -47,6 +57,7 @@ declare const _default: {
|
|
|
47
57
|
isSchedule: (value: unknown) => boolean;
|
|
48
58
|
isConnection: (value: unknown) => value is ConnectionDefinition;
|
|
49
59
|
isElement: (value: unknown) => value is Element;
|
|
60
|
+
toObject: (value: unknown) => object;
|
|
50
61
|
};
|
|
51
62
|
};
|
|
52
63
|
export default _default;
|
package/dist/util.js
CHANGED
|
@@ -8,7 +8,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.lowerCaseHeaders = void 0;
|
|
11
|
+
exports.toObject = exports.lowerCaseHeaders = void 0;
|
|
12
12
|
/** */
|
|
13
13
|
const parseISO_1 = __importDefault(require("date-fns/parseISO"));
|
|
14
14
|
const isValid_1 = __importDefault(require("date-fns/isValid"));
|
|
@@ -449,7 +449,8 @@ const isJSON = (value) => {
|
|
|
449
449
|
return false;
|
|
450
450
|
}
|
|
451
451
|
};
|
|
452
|
-
/**
|
|
452
|
+
/**
|
|
453
|
+
* This function accepts an arbitrary object/value and safely serializes it (handles cyclic references).
|
|
453
454
|
*
|
|
454
455
|
* @param value Arbitrary object/value to serialize.
|
|
455
456
|
* @returns JSON serialized text that can be safely logged.
|
|
@@ -461,9 +462,9 @@ const toJSON = (value) => {
|
|
|
461
462
|
/**
|
|
462
463
|
* This function returns a lower cased version of the headers passed to it.
|
|
463
464
|
*
|
|
464
|
-
* - `lowerCaseHeaders({"Content-Type": "Application/JSON"}) will return {"content-type": "Application/JSON"}`
|
|
465
|
-
* - `lowerCaseHeaders({"Cache-Control": "max-age=604800"}) will return {"cache-control": "max-age=604800"}`
|
|
466
|
-
* - `lowerCaseHeaders({"Accept-Language": "en-us"}) will return {"accept-language": "en-us"}`
|
|
465
|
+
* - `lowerCaseHeaders({"Content-Type": "Application/JSON"})` will return `{"content-type": "Application/JSON"}`
|
|
466
|
+
* - `lowerCaseHeaders({"Cache-Control": "max-age=604800"})` will return `{"cache-control": "max-age=604800"}`
|
|
467
|
+
* - `lowerCaseHeaders({"Accept-Language": "en-us"})` will return `{"accept-language": "en-us"}`
|
|
467
468
|
* @param headers The headers to convert to lower case
|
|
468
469
|
* @returns This function returns a header object
|
|
469
470
|
* */
|
|
@@ -471,6 +472,24 @@ const lowerCaseHeaders = (headers) => Object.entries(headers).reduce((result, [k
|
|
|
471
472
|
return Object.assign(Object.assign({}, result), { [key.toLowerCase()]: val });
|
|
472
473
|
}, {});
|
|
473
474
|
exports.lowerCaseHeaders = lowerCaseHeaders;
|
|
475
|
+
/**
|
|
476
|
+
* This function parses a JSON string (if JSON) and returns an object, or returns the object.
|
|
477
|
+
*
|
|
478
|
+
* - `toObject('{"foo":"bar","baz":123}')` will return object `{foo: "bar", baz: 123}`
|
|
479
|
+
* - `toObject({foo:"bar",baz:123})` will return object `{foo: "bar", baz: 123}`
|
|
480
|
+
*
|
|
481
|
+
* @param value The JSON string or object to convert
|
|
482
|
+
* @returns This function returns an object, parsing JSON as necessary
|
|
483
|
+
*/
|
|
484
|
+
const toObject = (value) => {
|
|
485
|
+
if (typeof value === "string" && isJSON(value)) {
|
|
486
|
+
return JSON.parse(value);
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
return value;
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
exports.toObject = toObject;
|
|
474
493
|
exports.default = {
|
|
475
494
|
types: {
|
|
476
495
|
isBool,
|
|
@@ -504,5 +523,6 @@ exports.default = {
|
|
|
504
523
|
isSchedule,
|
|
505
524
|
isConnection,
|
|
506
525
|
isElement,
|
|
526
|
+
toObject: exports.toObject,
|
|
507
527
|
},
|
|
508
528
|
};
|