How to use xml-js - 10 common examples

To help you get started, we’ve selected a few xml-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vmware / clarity / latest / prerender.ts View on Github external
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const {
  AppServerModuleNgFactory,
  LAZY_MODULE_MAP
} = require("./dist/server/main");

// Path is relative to dist/ directory where it runs
const BROWSER_FOLDER = join(process.cwd(), "browser");
const OUTPUT_FOLDER = join(process.cwd(), argv.directory);
const SRC_FOLDER = join(process.cwd(), '../', 'src');

// Load the index.html file containing referances to your application bundle.
const index = readFileSync(join("browser", "index.html"), "utf8");
// Load the sitemap to know the list of urls to render
const sitemapFile = readFileSync(join(process.cwd(), "browser", "sitemap.xml"), {encoding: 'utf8'});
const sitemap = converter.xml2js(sitemapFile, {compact: true});

// Build an array of routes and paths, only render the current version docs
const urls = sitemap.urlset.url
  .filter(item => {
    // Filter out the docs from other versions
    if (item.loc._text.indexOf('/documentation/') > -1 && item.loc._text.indexOf('/documentation/' + environment.version) === -1) {
      return false;
    }
    return true;
  })
  .map(item => {
    const url = parse(item.loc._text);
    const route = url.pathname.replace("clarity/", "");
    const fullPath = join(BROWSER_FOLDER, route);

    // Make sure the directory structure is there
github vmware / clarity / latest / prerender.ts View on Github external
const notFound = () => {
  // Copy index.html from not-found to 404.html
  copySync(join(BROWSER_FOLDER, 'not-found', 'index.html'), join(BROWSER_FOLDER, '404.html'));
  // Remove not-found from sitemap
  const sitemapFile = readFileSync(join(BROWSER_FOLDER, "sitemap.xml"), {encoding: 'utf8'});
  const sitemap = converter.xml2js(sitemapFile, {compact: true});
  sitemap.urlset.url = sitemap.urlset.url.filter(item => {
    if (item.loc._text.indexOf('/not-found') >= 0) {
      return false;
    }
    return true;
  });
  writeFileSync(join(BROWSER_FOLDER, "sitemap.xml"), converter.js2xml(sitemap, {compact: true, spaces: 4}), {encoding: 'utf8'});
  // Delete the not-found directory
  del.sync([`${BROWSER_FOLDER}/not-found/**`]);
};
github idleberg / atomizr-cli / lib / converter / sublime.js View on Github external
var readXml = function (input, options) {
    var data, output;
    // Validate XML
    try {
        data = xml_js_1.xml2js(input, {
            spaces: 4,
            compact: true
        });
    }
    catch (error) {
        throw error;
    }
    var inputScope = (typeof data.snippet.scope['_text'] !== 'undefined') ? data.snippet.scope['_text'] : null;
    var scope = options.scope ? options.scope : inputScope;
    // Minimum requirements
    if (typeof data.snippet.content._cdata === 'undefined') {
        return console.warn('This doesn\'t seem to be a valid Sublime Text snippet file. Aborting.');
    }
    // Get scope, convert if necessary
    output = {};
    if (scope !== null) {
github aws-amplify / amplify-cli / packages / amplify-storage-simulator / src / server / S3server.ts View on Github external
private async handleRequestPut(request, response) {
    const directoryPath = normalize(join(String(this.localDirectoryPath), String(request.params.path)));
    ensureFileSync(directoryPath);
    // strip signature in android , returns same buffer for other clients
    var new_data = util.stripChunkSignature(request.body);
    // loading data in map for each part
    if (request.query.partNumber !== undefined) {
      this.upload_bufferMap[request.query.uploadId][request.query.partNumber] = request.body;
    } else {
      writeFileSync(directoryPath, new_data);
      // event trigger  to differentitiate between multipart and normal put
      let eventObj = this.createEvent(request);
      this.emit('event', eventObj);
    }
    response.send(xml(convert.json2xml(JSON.stringify('upload success'))));
  }
github captbaritone / webamp / modern / src / utils.ts View on Github external
export async function readXml(
  zip: JSZip,
  filepath: string
): Promise {
  const file = await getCaseInsensitveFile(zip, filepath);
  if (file == null) {
    return null;
  }
  const text = await file.async("text");
  // @ts-ignore Due to the way it's config object interface works, xml2js is
  // bascially impossible to type. For example, you can specify what key to use
  // for `elements`. We choose `children` but the types assume the default
  // `elements`.
  return xml2js(text, { compact: false, elementsKey: "children" });
}
github gruijter / netgear.js / netgear.js View on Github external
async getInfo() {
		try {
			const message = soap.getInfo(this.sessionId);
			const result = await this._makeRequest(soap.action.getInfo,	message);
			// const patchedBody = patchBody(result.body);
			// parse xml to json object
			const parseOptions = {
				compact: true, ignoreDeclaration: true, ignoreAttributes: true, spaces: 2,
			};
			const rawJson = parseXml.xml2js(result.body, parseOptions);
			const entries = rawJson['v:Envelope']['v:Body']['m:GetInfoResponse'];
			const info = {};
			Object.keys(entries).forEach((property) => {
				if (Object.prototype.hasOwnProperty.call(entries, property)) {
					info[property] = entries[property]._text;
				}
			});
			return Promise.resolve(info);
		} catch (error) {
			return Promise.reject(error);
		}
	}
github csegames / Camelot-Unchained / game / hud / src / components / fullscreen / AbilityBuilder / AbilityCreation / IconPicker.tsx View on Github external
private initializeIcons = async () => {
    const res = await request('get', ICONS_URL);

    // Comes in as xml. Need to convert to json.
    const data = JSON.parse(convert.xml2json(res.data));
    const icons: string[] = [];
    const elements = data.elements[0].elements;
    elements.slice(5, elements.length).forEach((element: any) => {
      icons.push('http://camelot-unchained.s3.amazonaws.com/' + element.elements[0].elements[0].text);
    });
    this.setState({ icons, loading: false });
  }
github crablar / podsheets / server / src / routes / podcasts.ts View on Github external
categories,
                    author: fullOwnerName,
                    date: e.createdAt.toISOString(),
                    // lat: 33.417974, //optional latitude field for GeoRSS
                    // long: -111.933231, //optional longitude field for GeoRSS
                    itunesAuthor: fullOwnerName,
                    itunesExplicit: false,
                    itunesSubtitle: e.summary,
                    itunesSummary: e.summary,
                    itunesDuration: Math.trunc(e.audioDuration),
                    itunesKeywords: ["javascript", "podcast"],
                });
            });

            // We manually add iTunes category because in the podcasts module it doesn't work
            const jsonFeed = JSON.parse(convert.xml2json(feed.xml(), { compact: false, spaces: 4 }));
            jsonFeed.elements[0].elements[0].elements.push({
                type: "element",
                name: "itunes:category",
                attributes: {
                    text: mainCategory,
                },
                elements: subCategory.length > 0 ? [{
                    type: "element",
                    name: "itunes:category",
                    attributes: {
                        text: subCategory,
                    },
                }]
                    :
                    [],
            });
github shroudedcode / apk-mitm / src / tasks / modify-netsec-config.ts View on Github external
)
  const config = fileXml['network-security-config'][0]

  // Remove certificate pinning rules
  // See https://developer.android.com/training/articles/security-config#pin-set
  delete config['pin-set']

  const overrides = (config['debug-overrides'] || (config['debug-overrides'] = [{}]))[0]
  const trustAnchors = (overrides['trust-anchors'] || (overrides['trust-anchors'] = [{}]))[0]
  const certificates = trustAnchors['certificates'] || (trustAnchors['certificates'] = [])

  if (!certificates.filter((c: any) => c._attributes.src === 'user').length) {
    certificates.push({ _attributes: { src: 'user' } })
  }

  await fs.writeFile(path, xml.js2xml(fileXml, { compact: true, spaces: 4 }))
}
github idleberg / atomizr-cli / lib / converter / sublime.js View on Github external
obj = {
            // _comment: ' ' + this.meta + ' ',
            snippet: {
                content: {
                    _cdata: input.completions[0].contents
                },
                tabTrigger: {
                    _text: input.completions[0].trigger
                },
                scope: {
                    _text: input.scope
                }
            }
        };
    }
    output = xml_js_1.js2xml(obj, {
        compact: true,
        spaces: 4
    });
    return output;
};
exports.writeXml = writeXml;

xml-js

A convertor between XML text and Javascript object / JSON text.

MIT
Latest version published 6 years ago

Package Health Score

65 / 100
Full package analysis