mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
xml-js: Provides its own types
This commit is contained in:
@@ -384,6 +384,12 @@
|
||||
"sourceRepoURL": "https://code.google.com/p/x2js/",
|
||||
"asOfVersion": "3.1.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "xml-js",
|
||||
"typingsPackageName": "xml-js",
|
||||
"sourceRepoURL": "https://github.com/nashwaan/xml-js",
|
||||
"asOfVersion": "1.0.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "@xmpp/jid",
|
||||
"typingsPackageName": "xmpp-jid",
|
||||
|
||||
Vendored
-82
@@ -1,82 +0,0 @@
|
||||
// Type definitions for xml-js 0.9.6
|
||||
// Project: https://github.com/nashwaan/xml-js
|
||||
// Definitions by: Denis Carriere <https://github.com/DenisCarriere>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export interface ElementCompact {
|
||||
[key: string]: any
|
||||
_attributes?: {
|
||||
[key: string]: number | number
|
||||
}
|
||||
_cdata?: string | number
|
||||
_comment?: string | number
|
||||
_declaration?: {
|
||||
_attributes?: {
|
||||
version?: string | number
|
||||
encoding?: string | number
|
||||
}
|
||||
}
|
||||
_text?: string | number
|
||||
}
|
||||
|
||||
export interface Element {
|
||||
attributes?: {
|
||||
[key: string]: string | number
|
||||
}
|
||||
cdata?: string | number
|
||||
comment?: string | number
|
||||
declaration?: {
|
||||
attributes?: {
|
||||
version: string | number
|
||||
encoding: string | number
|
||||
}
|
||||
}
|
||||
elements?: Array<Element>
|
||||
text?: string | number
|
||||
type?: string | number
|
||||
name?: string | number
|
||||
}
|
||||
|
||||
declare namespace Options {
|
||||
interface XML2JS extends ChangingKeyNames, IgnoreOptions {
|
||||
compact?: boolean
|
||||
spaces?: number | string
|
||||
trim?: boolean
|
||||
sanitize?: boolean
|
||||
nativeType?: boolean
|
||||
addParent?: boolean
|
||||
alwaysChildren?: boolean
|
||||
}
|
||||
|
||||
interface JS2XML extends ChangingKeyNames, IgnoreOptions {
|
||||
spaces?: number | string
|
||||
compact?: boolean
|
||||
fullTagEmptyElement?: boolean
|
||||
}
|
||||
|
||||
interface IgnoreOptions {
|
||||
ignoreDeclaration?: boolean
|
||||
ignoreAttributes?: boolean
|
||||
ignoreComment?: boolean
|
||||
ignoreCdata?: boolean
|
||||
ignoreText?: boolean
|
||||
}
|
||||
|
||||
interface ChangingKeyNames {
|
||||
declarationKey?: string
|
||||
attributesKey?: string
|
||||
textKey?: string
|
||||
cdataKey?: string
|
||||
commentKey?: string
|
||||
parentKey?: string
|
||||
typeKey?: string
|
||||
nameKey?: string
|
||||
elementsKey?: string
|
||||
}
|
||||
}
|
||||
|
||||
export function js2xml(json: Element | ElementCompact, options?: Options.JS2XML): string;
|
||||
export function json2xml(json: Element | ElementCompact, options?: Options.JS2XML): string;
|
||||
export function xml2json(xml: string, options?: Options.XML2JS): any;
|
||||
export function xml2js(xml: string, options?: Options.XML2JS): any;
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"xml-js-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
import { Element, ElementCompact } from 'xml-js'
|
||||
import * as convert from 'xml-js'
|
||||
|
||||
// Declaration
|
||||
const declarationCompact1: ElementCompact = { _declaration: { _attributes: { version: 2 } }};
|
||||
const declarationCompact2: ElementCompact = { _declaration: { _attributes: { version: '1.0', encoding: 'utf-8' }}};
|
||||
const declaration1: Element = { declaration: { }};
|
||||
const declaration2: Element = { declaration: { attributes: { version: '1.0', encoding: 'utf-8' }}};
|
||||
|
||||
// Comment
|
||||
const commentCompact: ElementCompact = { _comment : 'Hello, World!' };
|
||||
const comment: Element = { elements: [{ type: 'comment', comment: 'Hello, World!' }]};
|
||||
|
||||
// CDATA
|
||||
const cdataCompact: ElementCompact = { _cdata: '<foo></bar>' };
|
||||
const cdata: Element = { elements : [{ type: 'cdata', cdata: '<foo></bar>' }]};
|
||||
|
||||
// Element
|
||||
const elementCompact1: ElementCompact = { a: {} };
|
||||
const element1: Element = { elements:[{ type: 'element', name: 'a' }]};
|
||||
|
||||
const elementCompact2: ElementCompact = { a: { _attributes: { x: '1.234', y:'It\'s' }}};
|
||||
const element2: Element = { elements: [{ type: 'element', name: 'a', attributes: { x: '1.234', y: 'It\'s' }}]};
|
||||
|
||||
const elementCompact3: ElementCompact = { a: { _text: ' Hi ' }};
|
||||
const element3: Element = { elements:[{ type: 'element', name: 'a', elements: [{ type: 'text', text: ' Hi ' }]}]};
|
||||
|
||||
const elementCompact4: ElementCompact = { a: {}, b: {} };
|
||||
const element4: Element = { elements:[{ type: 'element', name: 'a' }, { type: 'element', name: 'b' }]};
|
||||
|
||||
const elementCompact5: ElementCompact = { a: { b: {} }};
|
||||
const element5: Element = { elements: [{ type: 'element', name: 'a', elements: [{ type: 'element', name: 'b' }]}]};
|
||||
|
||||
// xml2json
|
||||
const xml = `
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<note importance="high" logged="true">
|
||||
<title>Happy</title>
|
||||
<todo>Work</todo>
|
||||
<todo>Play</todo>
|
||||
</note>`;
|
||||
convert.xml2json(xml, { compact: true, spaces: 4 });
|
||||
convert.xml2json(xml, { compact: false });
|
||||
|
||||
// json2xml
|
||||
convert.json2xml({ a: {} }, { compact: true, spaces: 4 });
|
||||
convert.json2xml({ elements:[{ type: 'element', name: 'a' }]}, { compact: false });
|
||||
|
||||
Reference in New Issue
Block a user