From 507a8a52500f407f1f2c245945799f9acec375fd Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 21 Mar 2017 08:03:29 -0700 Subject: [PATCH] x2js: Provides its own types (#15263) (#15262) --- notNeededPackages.json | 6 + x2js/index.d.ts | 36 ----- x2js/tsconfig.json | 23 ---- x2js/x2js-tests.ts | 298 ----------------------------------------- 4 files changed, 6 insertions(+), 357 deletions(-) delete mode 100644 x2js/index.d.ts delete mode 100644 x2js/tsconfig.json delete mode 100644 x2js/x2js-tests.ts diff --git a/notNeededPackages.json b/notNeededPackages.json index 6080fdc4c2..af2743bacb 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -354,6 +354,12 @@ "sourceRepoURL": "https://github.com/vuejs/vue-router", "asOfVersion": "2.0.0" }, + { + "libraryName": "x2js", + "typingsPackageName": "x2js", + "sourceRepoURL": "https://code.google.com/p/x2js/", + "asOfVersion": "3.1.0" + }, { "libraryName": "@xmpp/jid", "typingsPackageName": "xmpp-jid", diff --git a/x2js/index.d.ts b/x2js/index.d.ts deleted file mode 100644 index 56ff735b38..0000000000 --- a/x2js/index.d.ts +++ /dev/null @@ -1,36 +0,0 @@ -// Type definitions for x2js -// Project: https://code.google.com/p/x2js/ -// Definitions by: Horiuchi_H -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -interface IX2JS { - new (config?: IX2JSOption): IX2JS; - - getVersion(): string; - - xml2json(dom: Node): T; - json2xml(json: T): Node; - xml_str2json(xml: string): T; - json2xml_str(json: T): string; - parseXmlString(xml: string): Node; - - asArray(prop: any): any[]; - asDateTime(key: string): string; - asXmlDateTime(date: Date): string; - asXmlDateTime(date: number): string; -} - -interface IX2JSOption { - escapeMode?: boolean; - attributePrefix?: string; - arrayAccessForm?: string; - emptyNodeForm?: string; - enableToStringFunc?: boolean; - arrayAccessFormPaths?: any[]; - skipEmptyTextNodesForObj?: boolean; - stripWhitespaces?: boolean; - datetimeAccessFormPaths?: any[]; -} - -declare var X2JS: IX2JS; - diff --git a/x2js/tsconfig.json b/x2js/tsconfig.json deleted file mode 100644 index 15e948c2ac..0000000000 --- a/x2js/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6", - "dom" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": false, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "x2js-tests.ts" - ] -} \ No newline at end of file diff --git a/x2js/x2js-tests.ts b/x2js/x2js-tests.ts deleted file mode 100644 index fcea1fe966..0000000000 --- a/x2js/x2js-tests.ts +++ /dev/null @@ -1,298 +0,0 @@ -// Create x2js instance with default config -var x2js = new X2JS(); - -// JSON to DOM -var xmlDoc = x2js.json2xml( - { - MyRoot: { - MyChild: 'my_child_value', - MyAnotherChild: 10, - MyArray: [ 'test', 'test2' ], - MyArrayRecords: [ - { - ttt: 'vvvv' - }, - { - ttt: 'vvvv2' - } - ] - } - } -); - - -// JSON to XML string -var xmlDocStr = x2js.json2xml_str( - { - MyRoot: { - MyChild: 'my_child_value', - MyAnotherChild: 10, - MyArray: [ 'test', 'test2' ], - MyArrayRecords: [ - { - ttt: 'vvvv' - }, - { - ttt: 'vvvv2' - } - ] - } - } -); - -console.log(xmlDocStr); - -// JSON arrays to string -var xmlDocStr = x2js.json2xml_str( - { - MyRoot: { - namedItemArray: { - item: [ - { first: 'success1' } , - { first: 'success2' } - ] - }, - namedArray: [ - { first: 'success1' } , - { first: 'success2' } - ], - justArray: [ 'just success1', 'just success2' ], - arrayWithAttrs: [ - { - _test: 'successAttr', - __text: 'success', - temp: 'successTemp' - }, - { - _test: 'successAttr2', - __text: 'success2', - temp: 'successTemp2' - } - ] - } - } -); - -console.log(xmlDocStr); - -// XML string to JSON -var xmlText = "Successddsfgdsdgfdgfd"; -var jsonObj = x2js.xml_str2json(xmlText); -console.log(jsonObj.MyOperation.test); - -// Array access form examples -console.log(x2js.asArray(jsonObj.MyOperation.test)[0]); -// Or old style (1.0.+): -var x2jsOld = new X2JS({arrayAccessForm: "property"}); -jsonObj = x2jsOld.xml_str2json(xmlText); -console.log("Old is " + jsonObj.MyOperation.test_asArray[0]); - -// XML/DOM to JSON -var xmlText = " - Success - TestText ddsfg TestText2 dsdgfdgfd" -xmlDoc = x2js.parseXmlString(xmlText); - -var jsonObj = x2js.xml2json(xmlDoc); -console.log(jsonObj.MyOperation.test); - -// Parsing XML attrs -var xmlText = "SUCCESS TXTSuccessddsfgdsdgfdgfd"; -var jsonObj = x2js.xml_str2json(xmlText); -console.log(jsonObj.MyOperation._myAttr); -console.log(jsonObj.MyOperation.test2._myAttr); -console.log(jsonObj.MyOperation.txtAttrChild._sAttr); -console.log(jsonObj.MyOperation.txtAttrChild.__text); -console.log(jsonObj.MyOperation.txtAttrChild.toString()); - -// JSON to XML attrs -var xmlDocStr = x2js.json2xml_str( - { - TestAttrRoot: { - _myAttr: 'myAttrValue', - MyChild: 'my_child_value', - MyAnotherChild: 10, - MyTextAttrChild: { - _myTextAttr: 'myTextAttrValue', - __text: 'HelloText' - } - } - } -); - -console.log(xmlDocStr); - -//Change prefix for attributes -var x2jsChangedAttrs = new X2JS({ - // XML attributes. Default is "_" - attributePrefix: "$" -}); -jsonObj = x2jsChangedAttrs.xml_str2json(xmlText); -console.log(jsonObj.MyOperation.$myAttr); -console.log(jsonObj.MyOperation.test2.$myAttr); -console.log(jsonObj.MyOperation.txtAttrChild.$sAttr); - -xmlDocStr = x2jsChangedAttrs.json2xml_str({ - TestAttrRoot: { - _myAttr: 'myAttrValue', - MyChild: 'my_child_value', - MyAnotherChild: 10, - MyTextAttrChild: { - $myTextAttr: 'myTextAttrValue', - __text: 'HelloText' - } - } - } -); - -console.log(xmlDocStr); - - -// Parse XML with namespaces -var xmlText = "SuccessddsfgdsdgfdgfdtestArrSize"; -var jsonObj = x2js.xml_str2json(xmlText); -console.log(jsonObj.MyOperation.test); -if (jsonObj.MyOperation.test2.item.length > 2) - console.log("Error! Incorrect array len!"); - -var testObjC = { - 'm:TestAttrRoot': { - '_tns:m': 'http://www.example.org', - '_tns:cms': 'http://www.example.org', - MyChild: 'my_child_value', - 'cms:MyAnotherChild': 'vdfd' - } -} - -// Parse JSON object with namespaces -var xmlDocStr = x2js.json2xml_str( - testObjC -); - -console.log(xmlDocStr); - -// Parse JSON object constructed with another NS-style -var testObjNew = { - TestAttrRoot: { - __prefix: 'm', - '_tns:m': 'http://www.example.org', - '_tns:cms': 'http://www.example.org', - MyChild: 'my_child_value', - MyAnotherChild: { - __prefix: 'cms', - __text: 'vdfd' - } - } -} - -// Parse JSON object with namespaces -var xmlDocStr = x2js.json2xml_str( - testObjNew -); - -console.log(xmlDocStr); - -// Parse XML with header -var xmlText = "\n" + - "XML HEADER SUCCESS!"; - -var jsonObj = x2js.xml_str2json(xmlText); -console.log(jsonObj.test); - -// Parse XML with CDATA -var xmlText = "simple success]]> "; - -var jsonObj = x2js.xml_str2json(xmlText); -console.log(jsonObj.test.data.toString()); -console.log(jsonObj.test.data.__cdata); -console.log(jsonObj.test.simple); - - -// Parse JSON object with CDATA -var xmlDocStr = x2js.json2xml_str( - jsonObj -); -console.log(xmlDocStr); - -// Parse JSON with emtpy attributes -var xmlDocStr = x2js.json2xml_str( - { - MyRoot: { - MyNullChild: null, - MyNullChild2: undefined, - MyAnotherChild: 10, - MyEmptyChild: { - _attr: "test" - }, - MyEmptyChild2: { - _attr: "test", - __text: "Empty Nodes Test" - } - } - } -); - -console.log(xmlDocStr); - -// Escaping XML characters -xmlDocStr = x2js.json2xml_str( - { - MyRoot: { - MyEscapeXmlChild: " & \" ' / ", - MyEscapeXmlChild2: { - _attr: "success", - __text: " & \" ' / " - }, - MyEscapeXmlChildNonString: false - } - } -); - -console.log(xmlDocStr); - -jsonObj = x2js.xml_str2json(xmlDocStr); -console.log(jsonObj.MyRoot.MyEscapeXmlChild); -console.log(jsonObj.MyRoot.MyEscapeXmlChild2.toString()); - -console.log(x2js.getVersion()); - -// Array access path demos -x2js = new X2JS({ - arrayAccessFormPaths: [ - "MyArrays.test4.item", - /.*\.test3\.item/ - ] -}); - -xmlText = "" + - "successsecond" + - "success" + - "success" + - "success" + - ""; - - -jsonObj = x2js.xml_str2json(xmlText); -console.log(jsonObj.MyArrays.test3.item[0]); -console.log(jsonObj.MyArrays.test4.item[0]); -console.log(jsonObj.MyArrays.test5.item); - -// Working with datetimes -x2js = new X2JS({ - datetimeAccessFormPaths: [ - "MyDts.testds", - /.*\.testdt.*/ - ] -}); - -xmlText = "" + - "2002-10-10T12:00:00+04:00" + - "2002-10-10T12:00:00Z" + - "2002-10-10T12:00:00" + - "2002-10-10T12:00:00Z" + - ""; -jsonObj = x2js.xml_str2json(xmlText); - -console.log(jsonObj.MyDts.testds); -console.log(jsonObj.MyDts.testdt1); -console.log(jsonObj.MyDts.testdt2); -console.log(x2js.asDateTime(jsonObj.MyDts.testdc)); -