UNPKG

graphile-settings

Version:
26 lines (25 loc) 844 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.safeInflection = safeInflection; exports.createAttributeInflector = createAttributeInflector; exports.fallbackTableType = fallbackTableType; function safeInflection(fn, fallback) { try { return fn() ?? fallback; } catch { return fallback; } } function createAttributeInflector(inflection) { return (attrName, codec) => { const attributeName = safeInflection(() => inflection._attributeName?.({ attributeName: attrName, codec }), attrName); return safeInflection(() => inflection.camelCase?.(attributeName), attributeName); }; } function fallbackTableType(codecName) { return codecName .replace(/_/g, ' ') .replace(/\b\w/g, (char) => char.toUpperCase()) .replace(/ /g, ''); }