Skip to content

Instantly share code, notes, and snippets.

View AbuzerAsif's full-sized avatar
😃
Writing Code and Having Fun :)

Abuzer Asif AbuzerAsif

😃
Writing Code and Having Fun :)
  • 127.0.0.1
View GitHub Profile
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'myCustomPipe'
})
export class MyCustomPipe implements PipeTransform {
transform(value: any, args?: any): any {
return value;
}
}
<h1>{{ 'Hello world' | myCustomPipe }}</h1> // Output is empty
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'myCustomPipe'
})
export class MyCustomPipe implements PipeTransform {
transform(value: any, args?: any): any {
return null;
}
}
<h1>{{ 500 | currency : 'GBP' }}</h1> // Output: £500
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
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
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
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!"}
const xml2js = require('xml2js');
const xml = '<root>Hello world!</root>'
xml2js.parseString(xml, function (err, result) {
console.log(result.root); // Output: Hello world!
});