Skip to content

Commit

Permalink
feat: use system EOL characters for file output
Browse files Browse the repository at this point in the history
  • Loading branch information
elyukai committed Feb 22, 2022
1 parent c8905cd commit 7df369e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/jsonSchema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EOL } from "os"
import { ChildNode, JSDoc, NodeKind, parentGroupToArray, RootNode, TokenKind } from "./ast"

/**
Expand Down Expand Up @@ -301,4 +302,4 @@ export const astToJsonSchema = (file: RootNode, schemaFileName: string): JsonSch
}

export const jsonSchemaToFileContent = (schema: JsonSchema): string =>
`${JSON.stringify(schema, undefined, 2)}\n`
`${JSON.stringify(schema, undefined, 2).replace(/\n/g, EOL)}${EOL}`
11 changes: 6 additions & 5 deletions src/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EOL } from "os"
import { ArrayNode, ChildNode, DictionaryNode, EnumerationNode, JSDoc, LiteralNode, NodeKind, parentGroupToArray, RecordNode, ReferenceNode, RootNode, TokenKind, TokenNode, TupleNode, UnionNode } from "./ast"

const h = (level: number, text: string, anchor?: string) => {
Expand Down Expand Up @@ -34,7 +35,7 @@ const headerWithDescription = (title: string, description: string | undefined) =
return title
}

return `${title}\n\n${description}`
return `${title}${EOL}${EOL}${description}`
}

namespace LabelledList {
Expand All @@ -60,7 +61,7 @@ namespace LabelledList {
: undefined

export const create = (items: (string | undefined)[]) =>
items.filter(item => item !== undefined).join("\n")
items.filter(item => item !== undefined).join(EOL)
}

type SimpleNode =
Expand Down Expand Up @@ -281,7 +282,7 @@ const strictObjectBody = (
a("See details", `#${propertyPropertyPath}`)
].join(" | ")
})
.join("\n")
.join(EOL)

const properties = Object.entries(node.elements)
.reduce<SectionNode>(
Expand Down Expand Up @@ -342,7 +343,7 @@ const strictObjectBody = (
LabelledList.line("Type", "Object"),
LabelledList.line("Minimum Properties", node.jsDoc?.tags.minProperties, icode),
]),
`Key | Description | Details\n:-- | :-- | :--\n${propertiesOverview}`,
`Key | Description | Details${EOL}:-- | :-- | :--${EOL}${propertiesOverview}`,
...properties.inline,
],
append: properties.append
Expand Down Expand Up @@ -428,5 +429,5 @@ export const astToMarkdown = (file: RootNode): string => {
docHeader(file, ref?.jsDoc),
h(2, "Definitions"),
...definitions
].join("\n\n") + "\n"
].join(EOL + EOL) + EOL
}

0 comments on commit 7df369e

Please sign in to comment.