UNPKG

@naimi/alib

Version:
96 lines (75 loc) 2.08 kB
require("./alib-print.js"); require("./alib-csv.js"); require("./alib-misc.js"); require("./alib-trnsp.js"); alib_root = __dirname.replace(/\\/g, "/");// + "/.." //! Shared lib between NodeJS and JScript var gl_var = 1; //! inside this module only gl_var = 1; //! global if (typeof jscript !== undefined) { try { alib_root = WScript.ScriptFullName.substring(0, WScript.ScriptFullName.lastIndexOf(WScript.ScriptName) - 1).replace(/\\/g, "/") + "/"; } catch (e) { console.log("ERROR " + e.number + ": " + e.description + " - alib_root (" + alib_root + ")\n"); } } //!--- misc functions addZero = function (i) { return (i > 9 ? '' : '0') + i; } var obj={} obj.PI = 3.14 obj.prototype = { area: function () { return obj.PI * this.radius * this.radius; } } var invisible = function () { console.log("invisible"); } var test = {}; test.f1 = function() { console.log('test'); } test = 5; x = function() { console.log('x!'); } //! convert all floats > int. works on any dimension arrays arr2fixed = function (arr, n, len) { if (typeof len == "undefined") len = 0; if (arr.length === len) return 0; if (Array.isArray(arr[len])) arr2fixed(arr[len], n); else arr[len] = parseFloat(arr[len].toFixed(n)); arr2fixed(arr, n, len + 1); } //! multiply all array elements by n. works on any dimension arrays arr_multiply = function (arr, n, len) { if (typeof len == "undefined") len = 0; if (arr.length === len) return 0; if (Array.isArray(arr[len])) arr_multiply(arr[len], n); else arr[len] = arr[len] * n; arr_multiply(arr, n, len + 1); } //! add n to all array elements. works on any dimension arrays arr_add = function (arr, n, len) { if (typeof len == "undefined") len = 0; if (arr.length === len) return 0; if (Array.isArray(arr[len])) arr_add(arr[len], n); else arr[len] = arr[len] + n; arr_add(arr, n, len + 1); } var exports = {} //! to bypass JScript error regarding exports exports.message = "test_msg"; exports.say = function () { console.log(exports.message); }