Skip to content

Commit

Permalink
Migrate types to use export system
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilym committed Aug 24, 2023
1 parent 06d6cbf commit 0a8c5eb
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { cdataTag, tag, tagXmlHeader } from './tags';
import type {
XMLObject,
GenerateXMLOptions,
XMLAttributes,
TagOptions,
XMLValueType,
} from './types';
import { handleStringify, replaceInvalidXmlElementBodyCharacters } from './utility';

/**
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { generateXMLFromObject } from './builder';
export { generateObjectFromXML } from './parser';
export type * from './types';
1 change: 1 addition & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import DomParser, { Node } from 'dom-parser';
import type { XMLObject } from './types';

interface CleanNode extends Node {
jsonName: string;
Expand Down
1 change: 1 addition & 0 deletions src/tags.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { TagOptions, XMLAttributes } from './types';
import { replaceInvalidXmlAttributeCharacters, replaceInvalidXmlCdataCharacters } from './utility';

/**
Expand Down
12 changes: 6 additions & 6 deletions src/main.d.ts → src/types.ts
Original file line number Diff line number Diff line change
@@ -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<SupportedDataTypes> | XMLObject | XMLObject[];
export type XMLValueType = SupportedDataTypes | Array<SupportedDataTypes> | XMLObject | XMLObject[];

interface GenerateXMLOptions {
export interface GenerateXMLOptions {
/** Whether to apply formatting */
pretty?: boolean;
/** The number of spaces to indent each level */
Expand All @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions src/utility.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 0a8c5eb

Please sign in to comment.