diff --git a/package.json b/package.json index 13df2fa..6454088 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.1.2", "description": "Build xml files from json objects", "main": "lib/index.js", - "types": "lib/main.d.ts", + "types": "lib/index.d.ts", "scripts": { "build": "tsc --project tsconfig.build.json", "lint": "eslint . --ext .ts", diff --git a/src/builder.ts b/src/builder.ts index 204d89f..8c77f12 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -1,4 +1,11 @@ import { cdataTag, tag, tagXmlHeader } from './tags'; +import type { + XMLObject, + GenerateXMLOptions, + XMLAttributes, + TagOptions, + XMLValueType, +} from './types'; import { handleStringify, replaceInvalidXmlElementBodyCharacters } from './utility'; /** diff --git a/src/index.ts b/src/index.ts index 935d2b7..c396e5e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,3 @@ export { generateXMLFromObject } from './builder'; export { generateObjectFromXML } from './parser'; +export type * from './types'; diff --git a/src/parser.ts b/src/parser.ts index 137eb32..4ba6af2 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -1,4 +1,5 @@ import DomParser, { Node } from 'dom-parser'; +import type { XMLObject } from './types'; interface CleanNode extends Node { jsonName: string; diff --git a/src/tags.ts b/src/tags.ts index a8f9778..8c18f84 100644 --- a/src/tags.ts +++ b/src/tags.ts @@ -1,3 +1,4 @@ +import type { TagOptions, XMLAttributes } from './types'; import { replaceInvalidXmlAttributeCharacters, replaceInvalidXmlCdataCharacters } from './utility'; /** diff --git a/src/main.d.ts b/src/types.ts similarity index 70% rename from src/main.d.ts rename to src/types.ts index f242740..f8d6350 100644 --- a/src/main.d.ts +++ b/src/types.ts @@ -1,16 +1,16 @@ -type XMLObject = { +export type XMLObject = { [key: string]: XMLValueType | undefined; }; -type XMLAttributes = { +export type XMLAttributes = { [key: string]: string; }; -type SupportedDataTypes = string | number | boolean | Date; +export type SupportedDataTypes = string | number | boolean | Date; -type XMLValueType = SupportedDataTypes | Array | XMLObject | XMLObject[]; +export type XMLValueType = SupportedDataTypes | Array | XMLObject | XMLObject[]; -interface GenerateXMLOptions { +export interface GenerateXMLOptions { /** Whether to apply formatting */ pretty?: boolean; /** The number of spaces to indent each level */ @@ -25,7 +25,7 @@ interface GenerateXMLOptions { formatDateFunction?: (date: Date) => string; } -interface TagOptions { +export interface TagOptions { /** The tag indentation depth */ depth: number; /** Whether to apply formatting */ diff --git a/src/utility.ts b/src/utility.ts index 29236a2..db6fc18 100644 --- a/src/utility.ts +++ b/src/utility.ts @@ -1,3 +1,5 @@ +import type { XMLValueType } from './types'; + /** * Replaces control characters with their escaped versions. * @param str - the string to replace the control characters in