Comparing version 1.2.0 to 1.3.0
{ | ||
"name": "martok", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -12,3 +12,3 @@ "main": "dist/index.js", | ||
"test": "jest", | ||
"special": "ts-node src/index.ts tests/comparisons/multi/taggedUnions -o ./schema/martok --package net.sarazan.martok --datePattern standard", | ||
"special": "ts-node src/index.ts tests/comparisons/single/numbers.d.ts -o ./schema/martok --package net.sarazan.martok --datePattern standard", | ||
"lint": "eslint . --ext .ts" | ||
@@ -15,0 +15,0 @@ }, |
@@ -74,3 +74,4 @@ Martok - Glory To Your Schema! | ||
* optional fields | ||
* Typescrupt "Utility" types (e.g. `Omit` and `Pick`) | ||
* Typescript "Utility" types (e.g. `Omit` and `Pick`) | ||
* Configurable numeric precision via the `@precision` jsdoc tag | ||
@@ -77,0 +78,0 @@ ### TODO |
import ts, { | ||
Declaration, | ||
factory, | ||
getAllJSDocTags, | ||
getJSDocReturnType, | ||
getJSDocTags, | ||
InternalSymbolName, | ||
@@ -26,2 +29,4 @@ isArrayTypeNode, | ||
import { Martok } from "../martok/Martok"; | ||
import { KotlinNumber } from "../kotlin/KotlinTypes"; | ||
import { startCase } from "lodash"; | ||
@@ -126,4 +131,5 @@ const QUESTION_TOKEN = factory.createToken(SyntaxKind.QuestionToken); | ||
return "String"; | ||
if (isNumericLiteral(type) || type.kind === SyntaxKind.NumberKeyword) | ||
return "Double"; | ||
if (isNumericLiteral(type) || type.kind === SyntaxKind.NumberKeyword) { | ||
return getNumberType(type); | ||
} | ||
if (type.kind === SyntaxKind.BooleanKeyword) return "Boolean"; | ||
@@ -137,2 +143,15 @@ if (isArrayTypeNode(type)) { | ||
function getNumberType(node: TypeNode): KotlinNumber { | ||
let doc: ts.Node = node.parent; | ||
if (isArrayTypeNode(doc)) doc = doc.parent; | ||
const tag = getJSDocPrecision(doc) ?? "double"; | ||
return startCase(tag) as KotlinNumber; | ||
} | ||
function getJSDocPrecision(node: ts.Node): string | undefined { | ||
return getJSDocTags(node).find((value) => { | ||
return value.tagName.text === "precision"; | ||
})?.comment as string; | ||
} | ||
/** | ||
@@ -139,0 +158,0 @@ * @throws TaggedUnionError |
248232
151
4337
81