UNPKG

@sirhc77/postman-sdk-gen

Version:

Generate a fully-typed TypeScript SDK from a Postman collection, with support for Axios or Fetch, folder-based namespacing, and auto-inferred types.

36 lines (35 loc) 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.camelCase = camelCase; exports.capitalize = capitalize; exports.pascalCase = pascalCase; exports.namespaceToTypeName = namespaceToTypeName; function camelCase(input) { return input .toLowerCase() .split(/[^a-zA-Z0-9]+/) // split on non-alphanumeric characters .filter(Boolean) // remove empty strings .filter(value => value.toUpperCase() !== 'A' && value.toUpperCase() !== 'AN' && value.toUpperCase() !== 'THE') .map((word, index) => { if (index === 0) return word; return word[0].toUpperCase() + word.slice(1); }) .join(''); } function capitalize(input) { if (!input || input.length === 0) return input; return input[0].toUpperCase() + input.slice(1); } function pascalCase(str) { return str .replace(/[-_]+/g, " ") .replace(/[^\w\s]/g, "") .replace(/\s+(.?)/g, (_, c) => c.toUpperCase()) .replace(/^\w/, c => c.toUpperCase()); } function namespaceToTypeName(path, methodName) { const nameParts = [...path, methodName || ""]; return pascalCase(nameParts.join(" ")) + "Namespace"; }