UNPKG

@naimi/alib

Version:
79 lines (69 loc) 2.49 kB
//! nodejs only lib jscript = 0; //0: node, else: JScript WScript = {}; // require('c:/TotalCMD/usr/bin/alib.js') // Shared lib between NodeJS and JScript // import * as alib from "../shared/alib.js" // Shared lib between NodeJS and JScript fs = require('fs'); // var util = require("util"), // http = require("http"); var alib = require('../shared/alib'); console.log(alib.default); const stringify = require("json-stringify-pretty-compact"); del = function (fn) { try { if (fn.includes("function")) { console.log("del - wrong fn: " + fn); return -1; } // console.log('Deleting '+fn); // var fs = require('fs'); fs.unlink(fn, function (error) { if (error) { console.log("del - wrong fn2: " + error); // throw error; } // console.log('Deleted '+fn); }); } catch (err) { console.log(err.message); } } // a.myFunc(); // alib.default.say(); // myFunc(); // var options = { // // host: "www.google.com", // // host: "https://finance.yahoo.com/quote/TOT", // // host: "finance.yahoo.com/quote/TOT", // // host: "www.barrons.com/quote/stock/us/xnys/tot/research-ratings", // port: 80, // path: "/" // }; // var content = ""; // // var req = http.request(options, function(res) { // // var req = https.request("https://www.barrons.com/quote/stock/us/xnys/tot/research-ratings", function(res) { // var req = http.request("http://finance.yahoo.com/quote/TOT", function(res) { // res.setEncoding("utf8"); // res.on("data", function (chunk) { // content += chunk; // }); // res.on("end", function () { // util.log(content); // // fs.writeFile('dl/most_active.json', JSON.stringify(page, null, 2) , function(err) { // fs.writeFile('a', content , function(err) { // if(err) { // return console.log(err); // } // console.log("The file was saved!"); // }); // }); // }); // req.end(); beautify = function (str) { var json_opts = { indent: 2, // Defaults to 2. Works exactly like the third parameter of JSON.stringify. maxLength: 67,//Defaults to 80. Lines will be tried to be kept at maximum this many characters long. Infinity // replacer: undefined, //Defaults to undefined. Works exactly like the second parameter of JSON.stringify. } return stringify(JSON.parse(str), json_opts) }