Skip to content

Commit

Permalink
additional cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pgoldrbx committed Feb 29, 2020
1 parent 9196241 commit 5a51905
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// see: http://www.jsonml.org/syntax/

export type AttributeValue = string | number | boolean | null;

export interface Attributes {
Expand All @@ -15,7 +17,6 @@ interface ElementWithoutAttributes extends Array<TagName | Element> {
0: TagName;
}

// see: http://www.jsonml.org/syntax/
export type Element
= ElementWithAttributes
| ElementWithoutAttributes
Expand All @@ -26,7 +27,7 @@ export type ElementList = Array<Element | ElementList> | 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;

Expand All @@ -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;

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 5a51905

Please sign in to comment.