Skip to content

Instantly share code, notes, and snippets.

Avatar
😃
Writing Code and Having Fun :)

Abuzer Asif AbuzerAsif

😃
Writing Code and Having Fun :)
View GitHub Profile
View nodejs-xml-to-json-5.js
const xml2js = require('xml2js');
const productXML = '<Product><ID>10</ID><Name>Pizza</Name></Product>';
xml2js.parseString(productXML, { explicitArray : false }, function (err, result) {
// console.dir will allow us to print the whole object in our console
console.dir(result); // Output: { Product: { ID: '10', Name: 'Pizza' } }
console.dir(result.Product); // Output: { ID: '10', Name: 'Pizza' }
console.log(result.Product.ID); // Output: 10
console.log(result.Product.Name); // Output: Pizza
View nodejs-xml-to-json-4.js
const xml2js = require('xml2js');
const productXML = '<Product><ID>10</ID><Name>Pizza</Name></Product>';
xml2js.parseString(productXML, { explicitArray : false }, function (err, result) {
// console.dir will allow us to print the whole object in our console
console.dir(result); // Output: { Product: { ID: '10', Name: 'Pizza' } }
console.dir(result.Product); // Output: { ID: '10', Name: 'Pizza' }
console.log(result.Product.ID); // Output: 10
console.log(result.Product.Name); // Output: Pizza
View nodejs-xml-to-json-3.js
const xml2js = require('xml2js');
const productXML = '<Product><ID>10</ID><Name>Pizza</Name></Product>';
xml2js.parseString(productXML, function (err, result) {
// console.dir will allow us to print the whole object in our console
console.dir(result); // Output: { Product: { ID: [ '10' ], Name: [ 'Pizza' ] } }
console.dir(result.Product); // Output: { ID: [ '10' ], Name: [ 'Pizza' ] }
console.log(result.Product.ID[0]); // Output: 10
console.log(result.Product.Name[0]); // Output: Pizza
View nodejs-xml-to-json-package-json-1.json
{
"name": "nodejs xml to json",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT"
View nodejs-xml-to-json-2.js
const xml2js = require('xml2js');
const xml = '<root>Hello world!</root>'
xml2js.parseString(xml, function (err, result) {
console.log(result.root); // Output: Hello world!
const json = JSON.stringify(result);
console.log(json); // Output: {"root":"Hello world!"}
View nodejs-xml-to-json-1.js
const xml2js = require('xml2js');
const xml = '<root>Hello world!</root>'
xml2js.parseString(xml, function (err, result) {
console.log(result.root); // Output: Hello world!
});
View gist:ad08ce03807256ead7b8b70c46c2df08
app.filter('bytes', function() {
return function(bytes, precision) {
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
if (typeof precision === 'undefined') precision = 1;
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
number = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
}
});
@AbuzerAsif
AbuzerAsif / angularjs-interceptor.js
Last active May 8, 2018 — forked from edysegura/angularjs-interceptor.js
[angularjs] How to create an AngularJS HTTP Interceptor
View angularjs-interceptor.js
// Intercepting HTTP calls with AngularJS.
angular.module('MyApp', [])
.config(function ($provide, $httpProvider) {
// Add the interceptor to the $httpProvider.
$httpProvider.interceptors.push('MyHttpInterceptor');
})
// Intercept http calls.
.factory('MyHttpInterceptor', function ($q) {
return {
@AbuzerAsif
AbuzerAsif / .jsbeautifyrc
Created Apr 20, 2018 — forked from wzup/.jsbeautifyrc
.jsbeautifyrc file example
View .jsbeautifyrc
{
// The plugin looks for a .jsbeautifyrc file in the same directory as the
// source file you're prettifying (or any directory above if it doesn't exist,
// or in your home folder if everything else fails) and uses those options
// along the default ones.
// Details: https://github.com/victorporof/Sublime-HTMLPrettify#using-your-own-jsbeautifyrc-options
// Documentation: https://github.com/einars/js-beautify/
"html": {
"allowed_file_extensions": ["htm", "html", "xhtml", "shtml", "xml", "svg", "dust"],