Socket
Socket
Sign inDemoInstall

js2xmlparser

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js2xmlparser - npm Package Compare versions

Comparing version 2.0.2 to 3.0.0

README.md

6

CHANGES.md

@@ -0,1 +1,7 @@

## 3.0.0 ##
* Bug fixes
* Add null and undefined in type declarations
* Remove explicit engines requirement
## 2.0.2 ##

@@ -2,0 +8,0 @@

28

lib/main.d.ts

@@ -1,16 +0,1 @@

/**
* Copyright (C) 2016 Michael Kourlas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { IOptions } from "./options";

@@ -20,11 +5,10 @@ /**

*
* @param {string} root The name of the root XML element. When the
* object is converted to XML, it will be a
* child of this root element.
* @param {*} object The object to convert to XML.
* @param {IOptions} [options] Options for parsing the object and
* formatting the resulting XML.
* @param root The name of the root XML element. When the object is converted
* to XML, it will be a child of this root element.
* @param object The object to convert to XML.
* @param options Options for parsing the object and formatting the resulting
* XML.
*
* @returns {string} An XML string representation of the specified object.
* @returns An XML string representation of the specified object.
*/
export declare function parse(root: string, object: any, options?: IOptions): string;

@@ -0,3 +1,4 @@

"use strict";
/**
* Copyright (C) 2016 Michael Kourlas
* Copyright (C) 2016-2017 Michael Kourlas
*

@@ -16,14 +17,12 @@ * Licensed under the Apache License, Version 2.0 (the "License");

*/
"use strict";
var xmlcreate_1 = require("xmlcreate");
var options_1 = require("./options");
var utils_1 = require("./utils");
var xmlcreate_1 = require("xmlcreate");
/**
* Parses a string into XML.
*
* @param {string} str The string to parse into XML.
* @param {XmlAttribute|XmlElement} parentElement The XML element or attribute
* that will contain the string.
* @param {IOptions} options Options for parsing the
* string into XML.
* @param str The string to parse into XML.
* @param parentElement The XML element or attribute that will contain the
* string.
* @param options Options for parsing the string into XML.
*

@@ -39,15 +38,20 @@ * @private

};
if (parentElement instanceof xmlcreate_1.XmlElement && requiresCdata(str)) {
var cdataStrs = str.split("]]>");
for (var i = 0; i < cdataStrs.length; i++) {
if (requiresCdata(cdataStrs[i])) {
parentElement.cdata(cdataStrs[i]);
if (parentElement instanceof xmlcreate_1.XmlElement) {
if (requiresCdata(str)) {
var cdataStrs = str.split("]]>");
for (var i = 0; i < cdataStrs.length; i++) {
if (requiresCdata(cdataStrs[i])) {
parentElement.cdata(cdataStrs[i]);
}
else {
parentElement.charData(cdataStrs[i]);
}
if (i < cdataStrs.length - 1) {
parentElement.charData("]]>");
}
}
else {
parentElement.text(cdataStrs[i]);
}
if (i < cdataStrs.length - 1) {
parentElement.text("]]>");
}
}
else {
parentElement.charData(str);
}
}

@@ -61,7 +65,6 @@ else {

*
* @param {string} name The name of the attribute.
* @param {string} value The value of the attribute.
* @param {XmlElement} parentElement The XML element that will contain the
* string.
* @param {IOptions} options Options for parsing the attribute into XML.
* @param name The name of the attribute.
* @param value The value of the attribute.
* @param parentElement The XML element that will contain the string.
* @param options Options for parsing the attribute into XML.
*

@@ -72,5 +75,3 @@ * @private

var attribute = parentElement.attribute(name, "");
if (utils_1.isType(value, "String") || utils_1.isType(value, "Number")
|| utils_1.isType(value, "Boolean") || utils_1.isType(value, "Undefined")
|| utils_1.isType(value, "Null")) {
if (utils_1.isPrimitive(value)) {
parseString(utils_1.stringify(value), attribute, options);

@@ -87,9 +88,7 @@ }

*
* @param {string} key The key associated with the object or Map
* entry.
* @param {*} value The object or map entry.
* @param {XmlElement} parentElement The XML element that will contain the
* object or map entry.
* @param {IOptions} options Options for parsing the object or map
* entry into XML.
* @param key The key associated with the object or Map entry.
* @param value The object or map entry.
* @param parentElement The XML element that will contain the object or map
* entry.
* @param options Options for parsing the object or map entry into XML.
*

@@ -101,3 +100,3 @@ * @private

if (key === options.aliasString) {
if (!utils_1.isType(value, "String")) {
if (!utils_1.isString(value)) {
throw new Error("aliasString value for " + value

@@ -111,3 +110,3 @@ + " should be a string");

if (key.indexOf(options.attributeString) === 0) {
if (utils_1.isType(value, "Object")) {
if (utils_1.isObject(value)) {
for (var _i = 0, _a = Object.keys(value); _i < _a.length; _i++) {

@@ -126,5 +125,3 @@ var subkey = _a[_i];

if (key.indexOf(options.valueString) === 0) {
if (utils_1.isType(value, "String") || utils_1.isType(value, "Number")
|| utils_1.isType(value, "Boolean") || utils_1.isType(value, "Null")
|| utils_1.isType(value, "Undefined")) {
if (utils_1.isPrimitive(value)) {
parseValue(key, value, parentElement, options);

@@ -140,3 +137,3 @@ return;

var element = parentElement;
if (!utils_1.isType(value, "Array") && !utils_1.isType(value, "Set")) {
if (!utils_1.isArray(value) && !utils_1.isSet(value)) {
element = parentElement.element(key);

@@ -149,6 +146,5 @@ }

*
* @param {*} objectOrMap The object or map to parse into XML.
* @param {XmlElement} parentElement The XML element that will contain the
* object.
* @param {IOptions} options Options for parsing the object into XML.
* @param objectOrMap The object or map to parse into XML.
* @param parentElement The XML element that will contain the object.
* @param options Options for parsing the object into XML.
*

@@ -158,3 +154,3 @@ * @private

function parseObjectOrMap(objectOrMap, parentElement, options) {
if (utils_1.isType(objectOrMap, "Map")) {
if (utils_1.isMap(objectOrMap)) {
objectOrMap.forEach(function (value, key) {

@@ -174,9 +170,6 @@ parseObjectOrMapEntry(utils_1.stringify(key), value, parentElement, options);

*
* @param {string} key The key associated with the array or set to
* parse into XML.
* @param {*} arrayOrSet The array or set to parse into XML.
* @param {XmlElement} parentElement The XML element that will contain the
* function.
* @param {IOptions} options Options for parsing the array or set into
* XML.
* @param key The key associated with the array or set to parse into XML.
* @param arrayOrSet The array or set to parse into XML.
* @param parentElement The XML element that will contain the function.
* @param options Options for parsing the array or set into XML.
*

@@ -195,9 +188,9 @@ * @private

var arrayElement = parentElement;
if (!utils_1.isType(arrayNameFunc, "Undefined")) {
if (!utils_1.isUndefined(arrayNameFunc)) {
var arrayNameFuncKey = arrayNameFunc(arrayKey, arrayOrSet);
if (utils_1.isType(arrayNameFuncKey, "String")) {
if (utils_1.isString(arrayNameFuncKey)) {
arrayKey = arrayNameFuncKey;
arrayElement = parentElement.element(key);
}
else if (!utils_1.isType(arrayNameFuncKey, "Null")) {
else if (!utils_1.isNull(arrayNameFuncKey)) {
throw new Error("wrapHandlers function for " + arrayKey

@@ -209,3 +202,3 @@ + " should return a string or null");

var element = arrayElement;
if (!utils_1.isType(item, "Array") && !utils_1.isType(item, "Set")) {
if (!utils_1.isArray(item) && !utils_1.isSet(item)) {
element = arrayElement.element(arrayKey);

@@ -219,8 +212,6 @@ }

*
* @param {string} key The key associated with the value to parse
* into XML.
* @param {*} value The value to parse into XML.
* @param {XmlElement} parentElement The XML element that will contain the
* value.
* @param {IOptions} options Options for parsing the value into XML.
* @param key The key associated with the value to parse into XML.
* @param value The value to parse into XML.
* @param parentElement The XML element that will contain the value.
* @param options Options for parsing the value into XML.
*

@@ -240,10 +231,10 @@ * @private

}
if (!utils_1.isType(handler, "Undefined")) {
if (!utils_1.isUndefined(handler)) {
value = handler(value);
}
if (utils_1.isType(value, "Object") || utils_1.isType(value, "Map")) {
if (utils_1.isObject(value) || utils_1.isMap(value)) {
parseObjectOrMap(value, parentElement, options);
return;
}
if (utils_1.isType(value, "Array") || utils_1.isType(value, "Set")) {
if (utils_1.isArray(value) || utils_1.isSet(value)) {
parseArrayOrSet(key, value, parentElement, options);

@@ -257,9 +248,8 @@ return;

*
* @param {string} root The name of the root XML element. When the value is
* converted to XML, it will be a child of this root
* element.
* @param {*} value The value to convert to XML.
* @param {IOptions} options Options for parsing the value into XML.
* @param root The name of the root XML element. When the value is converted to
* XML, it will be a child of this root element.
* @param value The value to convert to XML.
* @param options Options for parsing the value into XML.
*
* @returns {XmlDocument} An XML document corresponding to the specified value.
* @returns An XML document corresponding to the specified value.
*

@@ -282,17 +272,15 @@ * @private

*
* @param {string} root The name of the root XML element. When the
* object is converted to XML, it will be a
* child of this root element.
* @param {*} object The object to convert to XML.
* @param {IOptions} [options] Options for parsing the object and
* formatting the resulting XML.
* @param root The name of the root XML element. When the object is converted
* to XML, it will be a child of this root element.
* @param object The object to convert to XML.
* @param options Options for parsing the object and formatting the resulting
* XML.
*
* @returns {string} An XML string representation of the specified object.
* @returns An XML string representation of the specified object.
*/
function parse(root, object, options) {
if (options === void 0) { options = {}; }
options = options_1.validateOptions(options);
var document = parseToDocument(root, object, options);
return document.toString(options.format);
var opts = new options_1.Options(options);
var document = parseToDocument(root, object, opts);
return document.toString(opts.format);
}
exports.parse = parse;

@@ -241,2 +241,21 @@ /**

/**
* Implementation of the IOptions interface used to provide default values
* to fields.
*
* @private
*/
export declare class Options implements IOptions {
aliasString: string;
attributeString: string;
cdataInvalidChars: boolean;
cdataKeys: string[];
declaration: DeclarationOptions;
dtd: DtdOptions;
format: FormatOptions;
typeHandlers: TypeHandlers;
valueString: string;
wrapHandlers: WrapHandlers;
constructor(options?: IOptions);
}
/**
* The options associated with the XML declaration. An example of an XML

@@ -256,3 +275,3 @@ * declaration is as follows:

/**
* The XML encoding to be included in the declaration. If defined, this +
* The XML encoding to be included in the declaration. If defined, this
* value must be a valid encoding. If left undefined, no encoding is

@@ -276,2 +295,15 @@ * included.

/**
* Implementation of the IDeclarationOptions interface used to provide default
* values to fields.
*
* @private
*/
export declare class DeclarationOptions implements IDeclarationOptions {
include: boolean;
encoding?: string;
standalone?: string;
version?: string;
constructor(declarationOptions?: IDeclarationOptions);
}
/**
* The options associated with the XML document type definition (DTD). An

@@ -297,3 +329,3 @@ * example of an XML document type definition is as follows:

/**
* The system identifier of the DTD, excluding quotation marks. If left
* The system identifier of the DTD, excluding quotation marks. If left
* undefined, no system identifier is included.

@@ -310,2 +342,15 @@ */

/**
* Implementation of the IDtdOptions interface used to provide default values
* to fields.
*
* @private
*/
export declare class DtdOptions implements IDtdOptions {
include: boolean;
name?: string;
sysId?: string;
pubId?: string;
constructor(dtdOptions?: IDtdOptions);
}
/**
* The options associated with the formatting of the XML document.

@@ -337,2 +382,15 @@ */

/**
* Implementation of the IFormatOptions interface used to provide default values
* to fields.
*
* @private
*/
export declare class FormatOptions implements IFormatOptions {
doubleQuotes?: boolean;
indent?: string;
newline?: string;
pretty?: boolean;
constructor(formatOptions?: IFormatOptions);
}
/**
* Map for the `typeHandlers` property in the {@link IOptions} interface.

@@ -348,2 +406,12 @@ */

/**
* Implementation of the ITypeHandlers interface used to provide default values
* to fields.
*
* @private
*/
export declare class TypeHandlers implements ITypeHandlers {
[type: string]: (value: any) => any;
constructor(typeHandlers?: ITypeHandlers);
}
/**
* Map for the `wrapHandlers` property in the {@link IOptions} interface.

@@ -361,14 +429,13 @@ */

*/
[key: string]: (key: string, value: any) => string;
[key: string]: (key: string, value: any) => string | null;
}
/**
* Validates an options object and replaces undefined values with their
* appropriate defaults.
* Implementation of the IWrapHandlers interface used to provide default values
* to fields.
*
* @param {IOptions} options The options object to validate.
*
* @returns {IOptions} The updated options object.
*
* @private
*/
export declare function validateOptions(options: IOptions): IOptions;
export declare class WrapHandlers implements IWrapHandlers {
[key: string]: (key: string, value: any) => string | null;
constructor(wrapHandlers?: IWrapHandlers);
}

@@ -19,203 +19,210 @@ /**

/**
* @private
*/
var defaults = {
aliasString: "=",
attributeString: "@",
cdataInvalidChars: false,
cdataKeys: [],
declaration: {
include: true
},
dtd: {
include: false
},
format: {},
typeHandlers: {},
valueString: "#",
wrapHandlers: {}
};
Object.freeze(defaults);
/**
* Validates the cdataKeys property of an options object.
* Implementation of the IOptions interface used to provide default values
* to fields.
*
* @param {string[]} cdataKeys The cdataKeys object.
*
* @returns {string[]} The updated cdataKeys object.
*
* @private
*/
function validateCdataKeys(cdataKeys) {
for (var _i = 0, cdataKeys_1 = cdataKeys; _i < cdataKeys_1.length; _i++) {
var key = cdataKeys_1[_i];
if (!utils_1.isType(key, "String")) {
throw new TypeError(key + " should be a string");
var Options = (function () {
function Options(options) {
if (options === void 0) { options = {}; }
this.aliasString = "=";
this.attributeString = "@";
this.cdataInvalidChars = false;
this.cdataKeys = [];
this.valueString = "#";
if (!utils_1.isObject(options)) {
throw new TypeError("options should be an Object or undefined");
}
if (!utils_1.isString(options.aliasString)) {
if (!utils_1.isUndefined(options.aliasString)) {
throw new TypeError("options.aliasString should be a string or"
+ " undefined");
}
}
else {
this.aliasString = options.aliasString;
}
if (!utils_1.isString(options.attributeString)) {
if (!utils_1.isUndefined(options.attributeString)) {
throw new TypeError("options.attributeString should be a string"
+ " or undefined");
}
}
else {
this.attributeString = options.attributeString;
}
if (!utils_1.isBoolean(options.cdataInvalidChars)) {
if (!utils_1.isUndefined(options.cdataInvalidChars)) {
throw new TypeError("options.cdataInvalidChars should be a"
+ " boolean or undefined");
}
}
else {
this.cdataInvalidChars = options.cdataInvalidChars;
}
if (!utils_1.isStringArray(options.cdataKeys)) {
if (!utils_1.isUndefined(options.cdataKeys)) {
throw new TypeError("options.cdataKeys should be an Array or" +
" undefined");
}
}
else {
this.cdataKeys = options.cdataKeys;
}
this.declaration = new DeclarationOptions(options.declaration);
this.dtd = new DtdOptions(options.dtd);
this.format = new FormatOptions(options.format);
this.typeHandlers = new TypeHandlers(options.typeHandlers);
if (!utils_1.isString(options.valueString)) {
if (!utils_1.isUndefined(options.valueString)) {
throw new TypeError("options.valueString should be a string"
+ " or undefined");
}
}
else {
this.valueString = options.valueString;
}
this.wrapHandlers = new WrapHandlers(options.wrapHandlers);
}
return cdataKeys;
}
return Options;
}());
exports.Options = Options;
/**
* Validates the declaration property of an options object.
* Implementation of the IDeclarationOptions interface used to provide default
* values to fields.
*
* @param {IDeclarationOptions} declaration The declaration object.
*
* @returns {IDeclarationOptions} The updated declaration object.
*
* @private
*/
function validateDecl(declaration) {
if (!utils_1.isType(declaration.include, "Boolean", "Undefined")) {
throw new TypeError("declaration.include should be a string or" +
" undefined");
var DeclarationOptions = (function () {
function DeclarationOptions(declarationOptions) {
if (declarationOptions === void 0) { declarationOptions = {}; }
this.include = true;
if (!utils_1.isObject(declarationOptions)) {
throw new TypeError("options.declaration should be an Object or"
+ " undefined");
}
if (!utils_1.isBoolean(declarationOptions.include)) {
if (!utils_1.isUndefined(declarationOptions.include)) {
throw new TypeError("options.declaration.include should be a"
+ " boolean or undefined");
}
}
else {
this.include = declarationOptions.include;
}
// Validation performed by xmlcreate
this.encoding = declarationOptions.encoding;
this.standalone = declarationOptions.standalone;
this.version = declarationOptions.version;
}
if (!utils_1.isType(declaration.include, "Boolean")) {
declaration.include = defaults.declaration.include;
}
return declaration;
}
return DeclarationOptions;
}());
exports.DeclarationOptions = DeclarationOptions;
/**
* Validates the dtd property of an options object.
* Implementation of the IDtdOptions interface used to provide default values
* to fields.
*
* @param {IDtdOptions} dtd The dtd object.
*
* @returns {IDtdOptions} The updated dtd object.
*
* @private
*/
function validateDtd(dtd) {
if (!utils_1.isType(dtd.include, "Boolean", "Undefined")) {
throw new TypeError("dtdOptions.include should be a string or" +
" undefined");
var DtdOptions = (function () {
function DtdOptions(dtdOptions) {
if (dtdOptions === void 0) { dtdOptions = {}; }
this.include = false;
if (!utils_1.isObject(dtdOptions)) {
throw new TypeError("options.dtd should be an Object or undefined");
}
if (!utils_1.isBoolean(dtdOptions.include)) {
if (!utils_1.isUndefined(dtdOptions.include)) {
throw new TypeError("options.dtd.include should be a boolean"
+ " or undefined");
}
}
else {
this.include = dtdOptions.include;
}
// Validation performed by xmlcreate
this.name = dtdOptions.name;
this.sysId = dtdOptions.sysId;
this.pubId = dtdOptions.pubId;
}
if (!utils_1.isType(dtd.include, "Boolean")) {
dtd.include = defaults.dtd.include;
}
return dtd;
}
return DtdOptions;
}());
exports.DtdOptions = DtdOptions;
/**
* Validates the typeHandlers property of an options object.
* Implementation of the IFormatOptions interface used to provide default values
* to fields.
*
* @param {ITypeHandlers} typeHandlers The typeHandlers object.
*
* @returns {ITypeHandlers} The updated typeHandlers object.
*
* @private
*/
function validateTypeHandlers(typeHandlers) {
for (var key in typeHandlers) {
if (typeHandlers.hasOwnProperty(key)) {
if (!utils_1.isType(typeHandlers[key], "Function")) {
throw new TypeError("options.typeHandlers['" + key + "']" +
" should be a Function");
}
var FormatOptions = (function () {
function FormatOptions(formatOptions) {
if (formatOptions === void 0) { formatOptions = {}; }
if (!utils_1.isObject(formatOptions)) {
throw new TypeError("options.format should be an Object or"
+ " undefined");
}
// Validation performed by xmlcreate
this.doubleQuotes = formatOptions.doubleQuotes;
this.indent = formatOptions.indent;
this.newline = formatOptions.newline;
this.pretty = formatOptions.pretty;
}
return typeHandlers;
}
return FormatOptions;
}());
exports.FormatOptions = FormatOptions;
/**
* Validates the wrapHandlers property of an options object.
* Implementation of the ITypeHandlers interface used to provide default values
* to fields.
*
* @param {IWrapHandlers} wrapHandlers The wrapHandlers object.
*
* @return {IWrapHandlers} The updated wrapHandlers object.
*
* @private
*/
function validateWrapHandlers(wrapHandlers) {
for (var key in wrapHandlers) {
if (wrapHandlers.hasOwnProperty(key)) {
if (!utils_1.isType(wrapHandlers[key], "Function")) {
throw new TypeError("options.wrapHandlers"
+ "['" + key + "'] should be a Function");
var TypeHandlers = (function () {
function TypeHandlers(typeHandlers) {
if (typeHandlers === void 0) { typeHandlers = {}; }
if (!utils_1.isObject(typeHandlers)) {
throw new TypeError("options.typeHandlers should be an Object or"
+ " undefined");
}
for (var key in typeHandlers) {
if (typeHandlers.hasOwnProperty(key)) {
if (!utils_1.isFunction(typeHandlers[key])) {
throw new TypeError("options.typeHandlers['" + key + "']" +
" should be a Function");
}
else {
this[key] = typeHandlers[key];
}
}
}
}
return wrapHandlers;
}
return TypeHandlers;
}());
exports.TypeHandlers = TypeHandlers;
/**
* Validates an options object and replaces undefined values with their
* appropriate defaults.
* Implementation of the IWrapHandlers interface used to provide default values
* to fields.
*
* @param {IOptions} options The options object to validate.
*
* @returns {IOptions} The updated options object.
*
* @private
*/
function validateOptions(options) {
if (!utils_1.isType(options.aliasString, "String", "Undefined")) {
throw new TypeError("options.aliasString should be a string or"
+ " undefined");
var WrapHandlers = (function () {
function WrapHandlers(wrapHandlers) {
if (wrapHandlers === void 0) { wrapHandlers = {}; }
if (!utils_1.isObject(wrapHandlers)) {
throw new TypeError("options.wrapHandlers should be an Object or"
+ " undefined");
}
for (var key in wrapHandlers) {
if (wrapHandlers.hasOwnProperty(key)) {
if (!utils_1.isFunction(wrapHandlers[key])) {
throw new TypeError("options.wrapHandlers['" + key + "']" +
" should be a Function");
}
else {
this[key] = wrapHandlers[key];
}
}
}
}
if (!utils_1.isType(options.aliasString, "String")) {
options.aliasString = defaults.aliasString;
}
if (!utils_1.isType(options.attributeString, "String", "Undefined")) {
throw new TypeError("options.attributeString should be a string or" +
" undefined");
}
if (!utils_1.isType(options.attributeString, "String")) {
options.attributeString = defaults.attributeString;
}
if (!utils_1.isType(options.cdataInvalidChars, "Boolean", "Undefined")) {
throw new TypeError("options.cdataInvalidChars should be a boolean or"
+ " undefined");
}
if (!utils_1.isType(options.cdataInvalidChars, "Boolean")) {
options.cdataInvalidChars = defaults.cdataInvalidChars;
}
if (!utils_1.isType(options.cdataKeys, "Array", "Undefined")) {
throw new TypeError("options.cdataKeys should be an Array or" +
" undefined");
}
if (!utils_1.isType(options.cdataKeys, "Array")) {
options.cdataKeys = defaults.cdataKeys;
}
options.cdataKeys = validateCdataKeys(options.cdataKeys);
if (!utils_1.isType(options.declaration, "Object", "Undefined")) {
throw new TypeError("options.declaration should be an Object or"
+ " undefined");
}
if (!utils_1.isType(options.declaration, "Object")) {
options.declaration = defaults.declaration;
}
options.declaration = validateDecl(options.declaration);
if (!utils_1.isType(options.dtd, "Object", "Undefined")) {
throw new TypeError("options.dtd should be an Object or undefined");
}
if (!utils_1.isType(options.dtd, "Object")) {
options.dtd = defaults.dtd;
}
options.dtd = validateDtd(options.dtd);
if (!utils_1.isType(options.format, "Object", "Undefined")) {
throw new TypeError("options.format should be an Object or undefined");
}
if (!utils_1.isType(options.format, "Object")) {
options.format = defaults.format;
}
if (!utils_1.isType(options.typeHandlers, "Object", "Undefined")) {
throw new TypeError("options.typeHandlers should be an Object or" +
" undefined");
}
if (!utils_1.isType(options.typeHandlers, "Object")) {
options.typeHandlers = defaults.typeHandlers;
}
options.typeHandlers = validateTypeHandlers(options.typeHandlers);
if (!utils_1.isType(options.valueString, "String", "Undefined")) {
throw new TypeError("options.valueString should be a string or" +
" undefined");
}
if (!utils_1.isType(options.valueString, "String")) {
options.valueString = defaults.valueString;
}
if (!utils_1.isType(options.wrapHandlers, "Object", "Undefined")) {
throw new TypeError("options.wrapHandlers should be an"
+ " Object or undefined");
}
if (!utils_1.isType(options.wrapHandlers, "Object")) {
options.wrapHandlers = defaults.wrapHandlers;
}
options.wrapHandlers = validateWrapHandlers(options.wrapHandlers);
return options;
}
exports.validateOptions = validateOptions;
return WrapHandlers;
}());
exports.WrapHandlers = WrapHandlers;

@@ -17,20 +17,57 @@ /**

/**
* Returns true if the specified value are of any of the specified types, as
* determined by the Object.prototype.toString.call function.
*
* @param {*} val The specified value.
* @param {...string[]} types The specified types.
*
* @returns {boolean} Whether or not the specified value are of any of the
* specified types.
*
* @private
*/
export declare function isType(val: any, ...types: string[]): boolean;
export declare function isString(val: any): val is string;
/**
* Converts a value into a string.
* @private
*/
export declare function isNumber(val: any): val is number;
/**
* @private
*/
export declare function isBoolean(val: any): val is boolean;
/**
* @private
*/
export declare function isUndefined(val: any): val is undefined;
/**
* @private
*/
export declare function isNull(val: any): val is null;
/**
* @private
*/
export declare function isPrimitive(val: any): val is (string | number | boolean | undefined | null);
/**
* @private
*/
export declare function isObject(val: any): val is Object;
/**
* @private
*/
export declare function isArray(val: any): val is any[];
/**
* @private
*/
export declare function isStringArray(val: any): val is string[];
/**
* @private
*/
export declare function isFunction(val: any): val is Function;
/**
* @private
*/
export declare function isSet(val: any): boolean;
/**
* @private
*/
export declare function isMap(val: any): boolean;
/**
* Returns a string representation of the specified value, as given by the
* value's toString() method (if it has one) or the global String() function
* (if it does not).
*
* @param {*} value The value to convert to a string.
* @param value The value to convert to a string.
*
* @returns {String} The string representation of the specified value.
* @returns A string representation of the specified value.
*

@@ -37,0 +74,0 @@ * @private

@@ -18,33 +18,106 @@ /**

/**
* Returns true if the specified value are of any of the specified types, as
* determined by the Object.prototype.toString.call function.
*
* @param {*} val The specified value.
* @param {...string[]} types The specified types.
*
* @returns {boolean} Whether or not the specified value are of any of the
* specified types.
*
* @private
*/
function isType(val) {
var types = [];
for (var _i = 1; _i < arguments.length; _i++) {
types[_i - 1] = arguments[_i];
function isString(val) {
return Object.prototype.toString.call(val) === "[object String]";
}
exports.isString = isString;
/**
* @private
*/
function isNumber(val) {
return Object.prototype.toString.call(val) === "[object Number]";
}
exports.isNumber = isNumber;
/**
* @private
*/
function isBoolean(val) {
return Object.prototype.toString.call(val) === "[object Boolean]";
}
exports.isBoolean = isBoolean;
/**
* @private
*/
function isUndefined(val) {
return Object.prototype.toString.call(val) === "[object Undefined]";
}
exports.isUndefined = isUndefined;
/**
* @private
*/
function isNull(val) {
return Object.prototype.toString.call(val) === "[object Null]";
}
exports.isNull = isNull;
/**
* @private
*/
function isPrimitive(val) {
return isString(val)
|| isNumber(val)
|| isBoolean(val)
|| isUndefined(val)
|| isNull(val);
}
exports.isPrimitive = isPrimitive;
/**
* @private
*/
function isObject(val) {
return Object.prototype.toString.call(val) === "[object Object]";
}
exports.isObject = isObject;
/**
* @private
*/
function isArray(val) {
return Object.prototype.toString.call(val) === "[object Array]";
}
exports.isArray = isArray;
/**
* @private
*/
function isStringArray(val) {
if (!isArray(val)) {
return false;
}
for (var _a = 0, types_1 = types; _a < types_1.length; _a++) {
var type = types_1[_a];
if (Object.prototype.toString.call(val) === "[object " + type + "]") {
return true;
for (var _i = 0, val_1 = val; _i < val_1.length; _i++) {
var entry = val_1[_i];
if (!isString(entry)) {
return false;
}
}
return false;
return true;
}
exports.isType = isType;
exports.isStringArray = isStringArray;
/**
* Converts a value into a string.
* @private
*/
function isFunction(val) {
return Object.prototype.toString.call(val) === "[object Function]";
}
exports.isFunction = isFunction;
/**
* @private
*/
function isSet(val) {
return Object.prototype.toString.call(val) === "[object Set]";
}
exports.isSet = isSet;
/**
* @private
*/
function isMap(val) {
return Object.prototype.toString.call(val) === "[object Map]";
}
exports.isMap = isMap;
/**
* Returns a string representation of the specified value, as given by the
* value's toString() method (if it has one) or the global String() function
* (if it does not).
*
* @param {*} value The value to convert to a string.
* @param value The value to convert to a string.
*
* @returns {String} The string representation of the specified value.
* @returns A string representation of the specified value.
*

@@ -54,4 +127,4 @@ * @private

function stringify(value) {
if (!isType(value, "Undefined") && !isType(value, "Null")) {
if (!isType(value.toString, "Function")) {
if (!isUndefined(value) && !isNull(value)) {
if (!isFunction(value.toString)) {
value = value.toString();

@@ -58,0 +131,0 @@ }

js2xmlparser
Copyright (C) 2016 Michael Kourlas
Copyright (C) 2016-2017 Michael Kourlas

@@ -9,2 +9,2 @@ ## Apache License, version 2.0 ##

xmlcreate
Copyright (C) 2016 Michael Kourlas
Copyright (C) 2016-2017 Michael Kourlas
{
"name": "js2xmlparser",
"version": "2.0.2",
"version": "3.0.0",
"description": "Parses JavaScript objects into XML",

@@ -27,3 +27,2 @@ "keywords": [

"NOTICE.md",
"npm-shrinkwrap.json",
"package.json",

@@ -39,20 +38,21 @@ "README.md"

"dependencies": {
"xmlcreate": "^0.1.1"
"xmlcreate": "^1.0.1"
},
"devDependencies": {
"@types/chai": "^3.4.35",
"@types/mocha": "^2.2.39",
"chai": "^3.5.0",
"es6-shim": "^0.35.1",
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-filter": "^4.0.0",
"gulp-mocha": "^3.0.1",
"gulp-sourcemaps": "^1.6.0",
"gulp-tslint": "^6.1.1",
"gulp-typedoc": "^2.0.0",
"gulp-typescript": "^2.13.6",
"merge2": "^1.0.2",
"mocha": "^3.0.2",
"tslint": "^3.15.1",
"typedoc": "^0.4.5",
"typings": "^1.3.3"
"gulp-mocha": "^4.0.1",
"gulp-sourcemaps": "^2.4.1",
"gulp-tslint": "^7.1.0",
"gulp-typedoc": "^2.0.2",
"gulp-typescript": "^3.1.5",
"merge2": "^1.0.3",
"mocha": "^3.2.0",
"tslint": "^4.4.2",
"typedoc": "^0.5.7",
"typescript": "^2.1.6"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc