From 5a51905cf32eb5fd023055cf5d9e1d5c272b771d Mon Sep 17 00:00:00 2001 From: Phil Gold Date: Sat, 29 Feb 2020 00:14:54 -0500 Subject: [PATCH] additional cleanup --- index.d.ts | 13 +++++++------ test/types.test.ts | 5 +++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/index.d.ts b/index.d.ts index 696a544..090a776 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1,5 @@ +// see: http://www.jsonml.org/syntax/ + export type AttributeValue = string | number | boolean | null; export interface Attributes { @@ -15,7 +17,6 @@ interface ElementWithoutAttributes extends Array { 0: TagName; } -// see: http://www.jsonml.org/syntax/ export type Element = ElementWithAttributes | ElementWithoutAttributes @@ -26,7 +27,7 @@ export type ElementList = Array | Element // Utils export function isFragment(jml: Element): boolean; -export function getTagName(jml: Element): string; +export function getTagName(jml: Element): TagName; export function isElement(value: any): boolean; @@ -40,7 +41,7 @@ export function addAttributes(jml: Element, attr: Attributes): void; export function getAttribute(jml: Element, key: string): AttributeValue | void; -export function setAttribute(jml: Element, key: string, value: any): void; +export function setAttribute(jml: Element, key: string, value: AttributeValue): void; export function appendChild(jml: Element, child: Element): boolean; @@ -55,11 +56,11 @@ type DOMNode = { // DOM -export type ElementFilterFunction = (jml: Element, elem: DOMNode) => Element | null; +export type ElementFilter = (jml: Element, elem: DOMNode) => Element | null; -export function fromHTML(elem: DOMNode, filter?: ElementFilterFunction): Element | null; +export function fromHTML(elem: DOMNode, filter?: ElementFilter): Element | null; -export function fromHTMLText(html: string, filter?: ElementFilterFunction): Element | null; +export function fromHTMLText(html: string, filter?: ElementFilter): Element | null; // HTML diff --git a/test/types.test.ts b/test/types.test.ts index 7046877..8db097e 100644 --- a/test/types.test.ts +++ b/test/types.test.ts @@ -28,8 +28,9 @@ const gotEmptyAttrs: Attributes = jsonml.getAttributes(['p'], false); const addAttributesRetval: void = jsonml.addAttributes(['p'], { foo: 'bar', a: 1 }); -const gotAttr: AttributeValue = jsonml.getAttribute(['p', { foo: 'bar' }], 'foo'); -const gotNoAttr: void = jsonml.getAttribute(['p', { foo: 'bar' }], 'this-does-not-exist'); +type MaybeAttributeValue = AttributeValue | void; +const gotAttr: MaybeAttributeValue = jsonml.getAttribute(['p', { foo: 'bar' }], 'foo'); +const gotNoAttr: MaybeAttributeValue = jsonml.getAttribute(['p', { foo: 'bar' }], 'this-does-not-exist'); const setAttributeRetval: void = jsonml.setAttribute(['p'], 'foo', 'bar');