#!/usr/bin/env node
#!/usr/bin/env node
'use strict';
const { ArgumentParser } = require('argparse');
const { version } = require('./package.json');
const parser = new ArgumentParser({
description: 'Argparse example'
});
parser.add_argument('-v', '--version', { action: 'version', version });
parser.add_argument('-f', '--foo', { help: 'foo bar' });
parser.add_argument('-b', '--bar', { help: 'bar foo' });
parser.add_argument('--baz', { help: 'baz bar' });
console.dir(parser.parse_args());
import Mercury from '@postlight/mercury-parser';
Mercury.parse(url).then(result => console.log(result));
// NOTE: When used in the browser, you can omit the URL argument
// and simply run `Mercury.parse()` to parse the current page.
const parse5 = require('parse5');
const documentFragment = parse5.parseFragment('<table></table>');
console.log(documentFragment.childNodes[0].tagName); //> 'table'
// Parses the html fragment in the context of the parsed <table> element.
const trFragment = parser.parseFragment(documentFragment.childNodes[0], '<tr><td>Shake it, baby</td></tr>');
console.log(trFragment.childNodes[0].childNodes[0].tagName); //> 'td'
const tsAst = recast.parse(source, {
parser: require("recast/parsers/typescript")
});
// Before rest parameters, "arguments" could be converted to a normal array using:
function f(a, b) {
let normalArray = Array.prototype.slice.call(arguments)
// -- or --
let normalArray = [].slice.call(arguments)
// -- or --
let normalArray = Array.from(arguments)
let first = normalArray.shift() // OK, gives the first argument
let first = arguments.shift() // ERROR (arguments is not a normal array)
}
// Now, you can easily gain access to a normal array using a rest parameter
function f(...args) {
let normalArray = args
let first = normalArray.shift() // OK, gives the first argument
}