graphile-build-pg
Version:
Build a GraphQL schema by reflection over a PostgreSQL schema. Easy to customize since it's built with plugins on graphile-build
37 lines (36 loc) • 913 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseTags = void 0;
const parseTags = str => {
return str.split(/\r?\n/).reduce((prev, curr) => {
if (prev.text !== "") {
return {
...prev,
text: `${prev.text}\n${curr}`
};
}
const match = curr.match(/^@[a-zA-Z][a-zA-Z0-9_]*($|\s)/);
if (!match) {
return {
...prev,
text: curr
};
}
const key = match[0].slice(1).trim();
const value = match[0] === curr ? true : curr.replace(match[0], "");
return {
...prev,
tags: {
...prev.tags,
[key]: !Object.prototype.hasOwnProperty.call(prev.tags, key) ? value : Array.isArray(prev.tags[key]) ? [...prev.tags[key], value] : [prev.tags[key], value]
}
};
}, {
tags: {},
text: ""
});
};
exports.parseTags = parseTags;
//# sourceMappingURL=utils.js.map