@graphql-markdown/helpers 1.0.0-next.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/LICENSE +21 -0
- package/README.md +4 -0
- package/dist/directives/descriptor.d.ts +2 -0
- package/dist/directives/descriptor.js +13 -0
- package/dist/directives/tag.d.ts +2 -0
- package/dist/directives/tag.js +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/utils/interpolate.d.ts +30 -0
- package/dist/utils/interpolate.js +48 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Grégory Heitz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# @graphql-markdown/helpers
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@graphql-markdown/helpers)
|
|
4
|
+
[](https://raw.githubusercontent.com/graphql-markdown/graphql-markdown/main/LICENSE)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.directiveDescriptor = void 0;
|
|
4
|
+
const graphql_1 = require("@graphql-markdown/graphql");
|
|
5
|
+
const interpolate_1 = require("../utils/interpolate");
|
|
6
|
+
function directiveDescriptor(directive, type, descriptionTemplate) {
|
|
7
|
+
const values = (0, graphql_1.getTypeDirectiveValues)(directive, type);
|
|
8
|
+
if (typeof descriptionTemplate !== "string") {
|
|
9
|
+
return (0, interpolate_1.interpolate)(directive.description ?? "", values);
|
|
10
|
+
}
|
|
11
|
+
return (0, interpolate_1.interpolate)(descriptionTemplate, values);
|
|
12
|
+
}
|
|
13
|
+
exports.directiveDescriptor = directiveDescriptor;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.directiveTag = void 0;
|
|
4
|
+
function directiveTag(directive, type, classname = "badge--secondary") {
|
|
5
|
+
return {
|
|
6
|
+
text: `@${directive.name}`,
|
|
7
|
+
classname: classname,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
exports.directiveTag = directiveTag;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./directives/descriptor"), exports);
|
|
18
|
+
__exportStar(require("./directives/tag"), exports);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Maybe } from "@graphql-markdown/types";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the value of the specified property or nested property of an object using a string path.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*
|
|
7
|
+
* @param path - property path as string.
|
|
8
|
+
* @param obj - the key/value record object.
|
|
9
|
+
* @param fallback - optional fallback value to be returned if the path cannot be resolved.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```js
|
|
13
|
+
* import { getObjPath } from '@graphql-markdown/utils/object';
|
|
14
|
+
*
|
|
15
|
+
* getObjPath("foo.bar", { foo: { bar: 42 } }); // Returns 42
|
|
16
|
+
*
|
|
17
|
+
* getObjPath("foo.bak", { foo: { bar: 42 } }, "fallback"); // Returns "fallback"
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @returns the property value if the path is resolved, else returns the `fallback` value.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
export declare function getObjPath(path: Maybe<string>, obj: unknown, fallback?: unknown): unknown;
|
|
24
|
+
/**
|
|
25
|
+
* interpolate
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
export declare function interpolate(template: string, variables: Maybe<Record<string, unknown>>, fallback?: string): string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interpolate = exports.getObjPath = void 0;
|
|
4
|
+
const utils_1 = require("@graphql-markdown/utils");
|
|
5
|
+
/**
|
|
6
|
+
* Returns the value of the specified property or nested property of an object using a string path.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*
|
|
10
|
+
* @param path - property path as string.
|
|
11
|
+
* @param obj - the key/value record object.
|
|
12
|
+
* @param fallback - optional fallback value to be returned if the path cannot be resolved.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* import { getObjPath } from '@graphql-markdown/utils/object';
|
|
17
|
+
*
|
|
18
|
+
* getObjPath("foo.bar", { foo: { bar: 42 } }); // Returns 42
|
|
19
|
+
*
|
|
20
|
+
* getObjPath("foo.bak", { foo: { bar: 42 } }, "fallback"); // Returns "fallback"
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @returns the property value if the path is resolved, else returns the `fallback` value.
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
function getObjPath(path, obj, fallback = "") {
|
|
27
|
+
if ((0, utils_1.isEmpty)(obj) || typeof path !== "string") {
|
|
28
|
+
return fallback;
|
|
29
|
+
}
|
|
30
|
+
return path
|
|
31
|
+
.split(".")
|
|
32
|
+
.reduce((res, key) => res[key] ?? fallback, obj); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
33
|
+
}
|
|
34
|
+
exports.getObjPath = getObjPath;
|
|
35
|
+
/**
|
|
36
|
+
* interpolate
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
function interpolate(template, variables, fallback) {
|
|
42
|
+
const regex = /\${[^{]+}/g;
|
|
43
|
+
return template.replace(regex, (match) => {
|
|
44
|
+
const objPath = match.slice(2, -1).trim();
|
|
45
|
+
return getObjPath(objPath, variables, fallback);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
exports.interpolate = interpolate;
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphql-markdown/helpers",
|
|
3
|
+
"homepage": "https://graphql-markdown.github.io",
|
|
4
|
+
"description": "GraphQL-Markdown customization helpers.",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/graphql-markdown/graphql-markdown/issues"
|
|
7
|
+
},
|
|
8
|
+
"version": "1.0.0-next.0",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "graphql-markdown/graphql-markdown",
|
|
13
|
+
"directory": "packages/helpers"
|
|
14
|
+
},
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Gregory Heitz"
|
|
17
|
+
},
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"require": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"default": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"./directives/*": {
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/directives/**.d.ts",
|
|
38
|
+
"default": "./dist/directives/**.js"
|
|
39
|
+
},
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/directives/**.d.ts",
|
|
42
|
+
"default": "./dist/directives/**.js"
|
|
43
|
+
},
|
|
44
|
+
"default": {
|
|
45
|
+
"types": "./dist/directives/**.d.ts",
|
|
46
|
+
"default": "./dist/directives/**.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"./package.json": "./package.json"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"prepack": "pinst --disable",
|
|
53
|
+
"postpack": "pinst --enable",
|
|
54
|
+
"stryker": "stryker run",
|
|
55
|
+
"clean": "rm -rf ./dist",
|
|
56
|
+
"docs": "typedoc"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@graphql-markdown/graphql": "^1.0.0-next.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@graphql-markdown/types": "^1.0.0-next.0"
|
|
63
|
+
},
|
|
64
|
+
"directories": {
|
|
65
|
+
"test": "tests"
|
|
66
|
+
},
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=16.14"
|
|
69
|
+
},
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"directory": "dist",
|
|
72
|
+
"access": "public"
|
|
73
|
+
},
|
|
74
|
+
"typescript": {
|
|
75
|
+
"definition": "dist/index.d.ts"
|
|
76
|
+
},
|
|
77
|
+
"files": [
|
|
78
|
+
"dist"
|
|
79
|
+
]
|
|
80
|
+
}
|