ninjs-lodash
Version:
lodash wrapper + utils
279 lines (228 loc) • 7.82 kB
JavaScript
const _ = require('./lib/lodash')
// _.each([435, 3398, 490398, '6485482', 6544528, 23483023, 3984578493, 30498505889, 9485039485039445], (val) => {
// _.log(`\nTesting : ${val}`)
// _.log(`bytes : ${_.bytes(val, 1)}`)
// _.log(`niceBytes : ${_.niceBytes(val)}`)
// })
// _.log(_.niceBytes(435)) // 435 bytes
// _.log(_.niceBytes(3398)) // 3.3 KB
// _.log(_.niceBytes(490398)) // 479 KB
// _.log(_.niceBytes(6544528)) // 6.2 MB
// _.log(_.niceBytes(23483023)) // 22 MB
// _.log(_.niceBytes(3984578493)) // 3.7 GB
// _.log(_.niceBytes(30498505889)) // 28 GB
// _.log(_.niceBytes(9485039485039445)) // 8.4 PB
// "bytes": bytes,
// "formatBytes": formatBytes,
// "prettyNumber": prettyNumber,
// "niceBytes": niceBytes,
// _.exec({ 'cmd': 'help' }, (err, res) => {
// if(err || res.err) return _.log(err || res.err)
// _.log(res.result)
// })
// const SRC = _.path.join('D:', 'storage', 'accounts', 'themes.json')
// _.readJson(SRC, (err, obj) => {
// _.jslog(obj)
// })
/**
* cproc (child_process)
*/
// _.exec({ cwd: 'F:\\libs\\sass', cmd:'npm', args: ['update'] }, function(err, result) { return _.log(result || 'Success but no stdout') })
// let myMap = new WeakMap()
// set()
// get()
// size
// clear()
// has()
// myMap.set('foo', 'bar')
// myMap.set('hello', 'world')
// Props
// console.log(myMap.set('foo', 'bar'))
// console.log(myMap.get('foo'))
// console.log(myMap.size)
// console.log(myMap.clear())
// console.log(myMap.size)
// console.log(myMap.has('foo'))
// Iterators
// console.log(myMap.keys())
// console.log(myMap.entries())
// console.log(myMap.values())
// Path -> _.path
// _.path.abs(src, ...args)
// _.log('_.path.abs(src, ...args) -> returns full absolute path of src (cwd + src if src isrelative)')
// _.log(_.path.abs('D:')) // false
// _.log(_.path.abs('D:', 'some', 'file.js')) // true
// // _.p(src, ...args) - alias for above _.path.abs
// _.log('_.p(src, ...args) -> returns full absolute path of src (cwd + src if src isrelative)')
// _.log(_.p('D:')) // false
// _.log(_.p('D:', 'some', 'file.js')) // true
// String
// _.log('_.isString(val, retFalseIfEmpty) -> returns true with empty string unless retFalseIfEmpty is truthy')
// _.log(_.isString('shiz')) // true
// _.log(_.isString('')) // true
// _.log(_.isString('', true)) // false
// _.log(_.isString(5)) // false
// _.log(_.isString(false)) // false
// _.log(_.isString(false, true)) // false
// _.log(_.isString([])) // false
// _.log(_.isString([], true)) // false
// _.log(_.isString({blah:[]})) // false
// _.log(_.isString({blah:[]}, true)) // false
// _.log('_.notString(val) -> returns true even with empty string')
// _.log(_.notString('shiz')) // false
// _.log(_.notString(5)) // true
// _.log(_.notString('')) // true
// _.log(_.notString(false)) // true
// _.log(_.notString([])) // true
// _.log(_.notString({blah:[]})) // true
// const SRC = _.path.join('D:', 'storage', 'accounts', 'themes.json')
// const _.abs()
// "isString": isString,
// "notString": notString,
/**
* NINJS-CMD
* common cli command runner
* os, processes, env, vars, npm, node, chrome, firefox,
* vscode, media-player, fs, notepad++, iis, firewall,
* jruler, snipping tool, google apps, safari, adobe, fw,
* word, powerpoint, outlook, excel, spotify, git
*/
// var _ = require('lodash'),
// path = require('path'),
// core = require('ninjs-core');
// exports = module.exports = constructor;
// _.assign(exports, {
// constructor: constructor
// });
// function constructor() {
// return "IMPLEMENT ME";
// }
// var _ = require("lodash"),
// path = require("path"),
// errors = require("./errors"),
// str = require("./str"),
// obj = require("./obj"),
// path = require("./path"),
// async = require("./async"),
// cache = require("./cache"),
// _debug = require('./debug'),
// debug = _debug("core"),
// log = require("./log"),
// _require = require("./require"),
// ps = require("./ps"),
// env = require("./env"),
// fs = require("./fs"),
// cls = require("./cls"),
// stubs = require("./stubs"),
// config = require("./config"),
// test = require("./test"),
// globals = require("./globals");
// // remapping keys so they do not override default _ methods
// var _cacheMixin = {
// getCache: _cache.get,
// setCache: _cache.set,
// unsetCache: _cache.unset,
// pushCache: _cache.push,
// clearCache: _cache.clear
// };
// var mixins = _.assign({}, _str, _path, _async, _cacheMixin);
// _.mixin(mixins);
// // PROCESS
// // cleanup cache refs, etc. when process exits
// ps.cleanup(function () {
// debug.log("process", "cleanup:begin", "ams");
// cache.clear();
// //debug.log("process", "cleanup:end", "ams", _.opt("messages.exit"));
// debug.log("process", "cleanup:end", "ams", "goodye");
// });
// /**
// * Exports
// */
// exports = module.exports = core;
// _.assign(exports, {
// introspect: introspect,
// envInfo: envInfo,
// errors: errors,
// str: str,
// obj: obj,
// path: path,
// async: async,
// cache: cache,
// debug: _debug,
// log: log,
// require: _require,
// ps: ps,
// env: env,
// fs: fs,
// cls: cls,
// stubs: stubs,
// config: config,
// globals: globals,
// test: test,
// _:_
// });
// // load config cache into mem
// // load();
// /**
// * Impl
// */
// // get main api or api[key]
// function core(key) { return key ? _.get(exports, key) || exports : exports; }
// function introspect(src, obj) {
// src = src || exports;
// obj = obj || {};
// _.forIn(src, function (v, k) {
// if (_.isFunction(v)) obj[k] = _.sig(v, k);
// if (_.isPlainObject(v)) {
// obj[k] = {};
// var ret = introspect(v, obj[k]);
// if (_.isEmpty(ret)) _.unset(obj, k);
// }
// });
// return obj;
// };
// function envInfo() {
// // var OPTIONS_SORT = ["env", "port", "start_time", "start_time_unix", "cwd", "appcmd", "ffmpeg",
// // "eol", "argv","source","target","vscode","json","debug","messages","errors"];
// return {
// global: global,
// env: process.env
// };
// }
// function load() {
// // config.load('config');
// // config.load('core');
// // config.load('debug');
// // config.load('errors');
// // config.load('json');
// // config.load('log');
// // config.load('messages');
// }
// /**
// * NINJS-CORE MIXINS
// */
// // var _ = require("lodash"),
// // path = require("path"),
// // moment = require('moment'),
// // _core = require("./core"),
// // _cls = require("./cls"),
// // _fs = require("./fs");
// // var mixins = _.merge({}, _core, _cls, _fs);
// // _.mixin(mixins);
// // // ~~~~~ Process/Env ~~~~~~
// // var START_TIME = moment.utc(),
// // CWD = process.cwd(),
// // ARG_V = _.jav(),
// // MY_CONFIG = _.setOpts('../../config/config') || {},
// // CWD_CONFIG = _.setOpts(path.join(CWD, 'config', 'config')) || {},
// // MERGED_SETTINGS = _.mcopy(_.get(_, 'options') || {}, MY_CONFIG, CWD_CONFIG);
// // _['options'] = _.merge(MERGED_SETTINGS, {
// // "env": _.get(ARG_V, 'env') || process.env['NODE_ENV'] || _.get(MERGED_SETTINGS, 'env'),
// // "port": _.get(ARG_V, 'port') || process.env['PORT'] || _.get(MERGED_SETTINGS, 'port') || 3000,
// // "cwd": CWD,
// // "start_time": START_TIME.format(),
// // "start_time_unix": START_TIME.valueOf(),
// // "argv": ARG_V
// // });
// // module.exports = _.acopy(mixins, { options: _['options'] });