@kubb/plugin-ts
Advanced tools
+12
-5
@@ -5,3 +5,2 @@ import { t as __name } from "./chunk-C0LytTxp.js"; | ||
| import { ast, defineGenerator, definePlugin, defineResolver } from "@kubb/core"; | ||
| import { isNumber } from "remeda"; | ||
| import ts from "typescript"; | ||
@@ -313,2 +312,5 @@ import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime"; | ||
| const { SyntaxKind, factory } = ts; | ||
| function isNumber(value) { | ||
| return typeof value === "number" && !Number.isNaN(value); | ||
| } | ||
| /** | ||
@@ -337,4 +339,9 @@ * TypeScript AST modifiers for common keywords (async, export, const, static). | ||
| if (!str.length || str.trim() !== str) return false; | ||
| const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest); | ||
| return !!node && node.kind === ts.SyntaxKind.Identifier && ts.identifierToKeywordKind(node.kind) === void 0; | ||
| let ch = str.codePointAt(0); | ||
| if (!ts.isIdentifierStart(ch, ts.ScriptTarget.Latest)) return false; | ||
| for (let i = ch > 65535 ? 2 : 1; i < str.length; i += ch > 65535 ? 2 : 1) { | ||
| ch = str.codePointAt(i); | ||
| if (!ts.isIdentifierPart(ch, ts.ScriptTarget.Latest)) return false; | ||
| } | ||
| return true; | ||
| } | ||
@@ -1629,6 +1636,6 @@ function propertyName(name) { | ||
| function sortParams(params) { | ||
| return [...params].sort((a, b) => rank(a) - rank(b)); | ||
| return params.toSorted((a, b) => rank(a) - rank(b)); | ||
| } | ||
| function sortChildParams(params) { | ||
| return [...params].sort((a, b) => rank(a) - rank(b)); | ||
| return params.toSorted((a, b) => rank(a) - rank(b)); | ||
| } | ||
@@ -1635,0 +1642,0 @@ /** |
+5
-6
| { | ||
| "name": "@kubb/plugin-ts", | ||
| "version": "5.0.0-beta.36", | ||
| "version": "5.0.0-beta.42", | ||
| "description": "Generate TypeScript types, interfaces, and enums from your OpenAPI specification. The foundational plugin that powers type safety across the entire Kubb ecosystem.", | ||
@@ -49,6 +49,5 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@kubb/core": "5.0.0-beta.36", | ||
| "@kubb/parser-ts": "5.0.0-beta.36", | ||
| "@kubb/renderer-jsx": "5.0.0-beta.36", | ||
| "remeda": "^2.37.0", | ||
| "@kubb/core": "5.0.0-beta.42", | ||
| "@kubb/parser-ts": "5.0.0-beta.42", | ||
| "@kubb/renderer-jsx": "5.0.0-beta.42", | ||
| "typescript": "^6.0.3" | ||
@@ -61,3 +60,3 @@ }, | ||
| "peerDependencies": { | ||
| "@kubb/renderer-jsx": "5.0.0-beta.36" | ||
| "@kubb/renderer-jsx": "5.0.0-beta.42" | ||
| }, | ||
@@ -64,0 +63,0 @@ "size-limit": [ |
+11
-15
@@ -8,5 +8,5 @@ <div align="center"> | ||
| [![npm downloads][npm-downloads-src]][npm-downloads-href] | ||
| [![Coverage][coverage-src]][coverage-href] | ||
| [![Stars][stars-src]][stars-href] | ||
| [![License][license-src]][license-href] | ||
| [![Sponsors][sponsors-src]][sponsors-href] | ||
| [![Node][node-src]][node-href] | ||
@@ -62,15 +62,11 @@ <h4> | ||
| [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-ts?flat&colorA=18181B&colorB=f58517 | ||
| [npm-version-href]: https://npmjs.com/package/@kubb/plugin-ts | ||
| [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-ts?flat&colorA=18181B&colorB=f58517 | ||
| [npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-ts | ||
| [license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517 | ||
| [npm-version-src]: https://shieldcn.dev/npm/v/@kubb/plugin-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark | ||
| [npm-version-href]: https://npmx.dev/package/@kubb/plugin-ts | ||
| [npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/plugin-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark | ||
| [npm-downloads-href]: https://npmx.dev/package/@kubb/plugin-ts | ||
| [stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark | ||
| [stars-href]: https://github.com/kubb-labs/kubb | ||
| [license-src]: https://shieldcn.dev/npm/license/@kubb/plugin-ts.svg?variant=secondary&size=xs&theme=zinc | ||
| [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE | ||
| [build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517 | ||
| [build-href]: https://www.npmjs.com/package/@kubb/plugin-ts | ||
| [minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-ts?style=flat&colorA=18181B&colorB=f58517 | ||
| [minified-href]: https://www.npmjs.com/package/@kubb/plugin-ts | ||
| [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517 | ||
| [coverage-href]: https://www.npmjs.com/package/@kubb/plugin-ts | ||
| [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517 | ||
| [sponsors-href]: https://github.com/sponsors/stijnvanhulle/ | ||
| [node-src]: https://shieldcn.dev/npm/node/@kubb/plugin-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark | ||
| [node-href]: https://npmx.dev/package/@kubb/plugin-ts |
+31
-5
| import { camelCase, pascalCase, screamingSnakeCase, snakeCase } from '@internals/utils' | ||
| import { ast } from '@kubb/core' | ||
| import { isNumber, sortBy } from 'remeda' | ||
| import ts from 'typescript' | ||
@@ -9,2 +8,16 @@ import { OPTIONAL_ADDS_UNDEFINED } from './constants.ts' | ||
| /** | ||
| * Compares two strings by UTF-16 code unit, keeping sorted output identical across platforms | ||
| * regardless of locale. | ||
| */ | ||
| function compareStrings(a: string, b: string): number { | ||
| if (a < b) return -1 | ||
| if (a > b) return 1 | ||
| return 0 | ||
| } | ||
| function isNumber(value: unknown): value is number { | ||
| return typeof value === 'number' && !Number.isNaN(value) | ||
| } | ||
| // https://ts-ast-viewer.com/ | ||
@@ -39,5 +52,18 @@ | ||
| } | ||
| const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest) | ||
| return !!node && node.kind === ts.SyntaxKind.Identifier && ts.identifierToKeywordKind(node.kind as unknown as ts.Identifier) === undefined | ||
| // Mirrors `ts.isIdentifierText`, which is not in the public type declarations. | ||
| // Walking by code point with `isIdentifierStart`/`isIdentifierPart` rejects | ||
| // invalid names such as private identifiers (`#FOO`), forcing `propertyName` | ||
| // to quote them. | ||
| let ch = str.codePointAt(0)! | ||
| if (!ts.isIdentifierStart(ch, ts.ScriptTarget.Latest)) { | ||
| return false | ||
| } | ||
| for (let i = ch > 0xffff ? 2 : 1; i < str.length; i += ch > 0xffff ? 2 : 1) { | ||
| ch = str.codePointAt(i)! | ||
| if (!ts.isIdentifierPart(ch, ts.ScriptTarget.Latest)) { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
@@ -389,3 +415,3 @@ | ||
| // Sort the imports alphabetically for consistent output across platforms | ||
| const sortedName = sortBy(name, [(item) => (typeof item === 'object' ? item.propertyName : item), 'asc']) | ||
| const sortedName = name.toSorted((a, b) => compareStrings(typeof a === 'object' ? a.propertyName : a, typeof b === 'object' ? b.propertyName : b)) | ||
@@ -449,3 +475,3 @@ return factory.createImportDeclaration( | ||
| // Sort the exports alphabetically for consistent output across platforms | ||
| const sortedName = sortBy(name, [(propertyName) => (typeof propertyName === 'string' ? propertyName : propertyName.text), 'asc']) | ||
| const sortedName = name.toSorted((a, b) => compareStrings(typeof a === 'string' ? a : a.text, typeof b === 'string' ? b : b.text)) | ||
@@ -452,0 +478,0 @@ return factory.createExportDeclaration( |
@@ -67,7 +67,7 @@ import { ast } from '@kubb/core' | ||
| function sortParams(params: ReadonlyArray<ast.FunctionParameterNode | ast.ParameterGroupNode>): Array<ast.FunctionParameterNode | ast.ParameterGroupNode> { | ||
| return [...params].sort((a, b) => rank(a) - rank(b)) | ||
| return params.toSorted((a, b) => rank(a) - rank(b)) | ||
| } | ||
| function sortChildParams(params: Array<ast.FunctionParameterNode>): Array<ast.FunctionParameterNode> { | ||
| return [...params].sort((a, b) => rank(a) - rank(b)) | ||
| return params.toSorted((a, b) => rank(a) - rank(b)) | ||
| } | ||
@@ -74,0 +74,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
577999
0.42%5
-16.67%6461
0.59%71
-5.33%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated