0.1.98 • Published 7 years ago

ninjs-lodash v0.1.98

Weekly downloads
4
License
AGPL-1.0
Repository
github
Last release
7 years ago

ninjs-lodash

*Super util library that exports extended Lodash object () via .mixin({...Super Util Methods....})*

Warning: The design of this module goes against standard coding practices. However, we are lazy, tired of import statements, and desire one core dependency module rather than thousands, hundreds of thousands, millions of module dependencies (each with overhead)


Overview

This module includes common utility methods that fall into the following groupings:

  • JavaScript Types -> String, Object, Array, Function, Number, Regx, Boolean, Date ....
  • Child Processes
  • Configuration/Settings -> Env, User, Local, Global, .Folders, .Files
  • Classes
  • OS
  • Paths
  • Urls
  • Debug
  • File System
  • Async
  • Terminal/CLI Helpers

This is the least dependent module (or most depended upon) module in the ninjs-* namespace.

The purpose of packaging all this functionality into one module was to make it easier/faster to create new modules and reduce code duplication/bloat

We tried to keep it as tiny as possible with as few dependencies as possible.

{
  "dependencies": {
    "async": "~2.1.2",
    "cli-color": "~1.1.0",
    "fs-extra": "~1.0.0",
    "glob": "~7.1.1",
    "lodash": "~4.16.6",
    "moment": "~2.15.2",
    "numeral": "~1.5.3"
  },
  "bundleDependencies": [],
  "peerDependencies": {},
  "devDependencies": {},
  "optionalDependencies": {}
}

Setup

Install

Install the module locally and add to ./package.json dependencies

npm install --save ninjs-lodash

Import

import 'ninjs-lodash' (instead of 'lodash')

Now you can use existing lodash utils AND/OR ninjs mixins

const _ = require('ninjs-lodash')

// ~~~~~ original lodash ~~~~~
_.each(['blah', 'item'], (item) => { ... })

// ~~~~~ ninjs-lodash mixins ~~~~~
_.async.waterfall([...], (err, result) { ... })

_.log(_.$('paths.root')) // prints path of dir containing package.json

$ettings

Override/Add your own $ettings

  • Create a ./.ninjs/settings.js(json) file within a module cwd that exports an object
  • You can now access that object (and nested props) via _.$()
  • internally uses _.get(settings, 'keypath'))
  • *Be careful not to override _.$() default settings
_.$('keypath.to.list[3]')

Scripts/Debugging

{
  "scripts": {
    "cli":        "set NODE_ENV=development && set DEBUG=* && node ./bin/cli.js",
    "cli-prod":   "set NODE_ENV=production && set DEBUG= && node ./bin/cli.js",
    "test":       "set NODE_ENV=development && set DEBUG=* && node ./test/index.js",
    "test-prod":  "set NODE_ENV=production && set DEBUG= && node ./test/index.js",
    "npm-config": "npm c ls -l"
  }
}

Be sure to add '--' before args/switches when running cli scriptsOtherwise switches will not be passed to the spawned process created by 'npm run script' command

npm run cli -- settings --key=paths

$ettings - Global Settings Cache

Override/Add your own $ettings

  • Create a ./.ninjs/settings.js(json) file within a module cwd that exports an object
  • You can now access that object (and nested props) via _.$()
  • internally uses _.get(settings, 'keypath'))
  • *Be careful not to override _.$() default settings
_.$('keypath.to.list[3]')

CLI Helper - _.cli(map)

Maps a terminal command to a Command Object and invokes its 'handler'

Command Object

{
  // command default options, args, switches
  "options": { key: '' },

  // command handler
  // options = _.merge(options, 'interpreted' options from command line args/switches)
  "handler": (options) => { /* Do Something -> run a command, invoke an api, .... */ },

  // command help (--help)
  "text": "This is printed when jav.key === settings && jav.isHelp",

  // command detailed help (--help -l)
  "body": "This is printed when jav.key === settings && jav.isHelp && jav.isLong.. If no body set -> obj.text is used instead"
}

Command Map

{
  "ams": {
    "module": {
      "publish": {
        "options": { "name": "" },
        "prop": (options, callback) => { return lib.publishModule(options, callback)  },
        "cb": (err, result) => { return err ? _.log(err) : _.jslog(result) }
      }
    }
  }
}

Example -> Invoke api.module.publish(options, cb) and print result

This is just an example api.module.publish does not exist

./package.json

{
  "bin": { "ninjs-lodash" : "./bin/cli.js" },
  "cli": "set NODE_ENV=development && set DEBUG=* && node ./bin/cli.js"
}

./bin/cli.js

exports = module.exports = { // Command Map
  "ams": {
    "module": {
      "publish": {
        "options": { "name": "" },
        "prop": (options, callback) => { return lib.publishModule(options, callback)  },
        "cb": (err, result) => { return err ? _.log(err) : _.jslog(result) },
        "text": "--help text",
        "body": "--help -l long text"
      }
    }
  }
}

_.cli(exports) // Run Interpreter

Terminal . (Local) -> npm run cli -- keypath.something.method --switches --k=v ...

> npm run cli -- api.module.publish --name=ninjs-lodash

Terminal * (Global) -> %cli-alias% keypath.something.method --switches --k=v ...

> ninjs-lodash api.module.publish --name=ninjs-lodash

NOTE: args/switches after '--' proxied to spawned npm run-script process


String

_.bytes(num)        // returns formatted byte string

Path

_.path[*]           // require('path') + extras
_.path.name(src)
_.path.dir(src)
_.path.base(src)
_.path.isAbsolute(src)

Url String

_.url[*]            // require('url') + extras

Plain Object

_.acopy(...args)    // _.assign with no mutation
_.mcopy(...args)    // _.merge with no mutation
_.deepExtend(o, ob) // deep merge

Array Object

_.args(...args)     // returns flattened array of args, args, string, ....

Async

_.async[*]          // require('async')
_.fail(err, cb)     // callback(err)
_.done(result, cb)  // callback(null, result)
_.cb(callback)      // callback || function noop() {}

File System

_[*fs]              // common fs-extra assigned to _
_.fs[*]             //  _.fs = require('fs-extra')

 

0.1.98

7 years ago

0.1.97

7 years ago

0.1.96

7 years ago

0.1.95

7 years ago

0.1.94

7 years ago

0.1.93

7 years ago

0.1.92

7 years ago

0.1.91

7 years ago

0.1.89

7 years ago

0.1.88

7 years ago

0.1.87

7 years ago

0.1.86

7 years ago

0.1.85

7 years ago

0.1.84

7 years ago

0.1.83

7 years ago

0.1.82

7 years ago

0.1.81

7 years ago

0.1.80

7 years ago

0.1.79

7 years ago

0.1.78

7 years ago

0.1.77

7 years ago

0.1.76

7 years ago

0.1.75

7 years ago

0.1.74

7 years ago

0.1.73

7 years ago

0.1.72

7 years ago

0.1.71

7 years ago

0.1.70

7 years ago

0.1.69

7 years ago

0.1.68

7 years ago

0.1.67

7 years ago

0.1.66

7 years ago

0.1.65

8 years ago

0.1.64

8 years ago

0.1.63

8 years ago

0.1.62

8 years ago

0.1.61

8 years ago

0.1.60

8 years ago

0.1.59

8 years ago

0.1.58

8 years ago

0.1.57

8 years ago

0.1.56

8 years ago

0.1.55

8 years ago

0.1.54

8 years ago

0.1.53

8 years ago

0.1.52

8 years ago

0.1.51

8 years ago

0.1.50

8 years ago

0.1.49

8 years ago

0.1.48

8 years ago

0.1.47

8 years ago

0.1.46

8 years ago

0.1.45

8 years ago

0.1.43

8 years ago

0.1.42

8 years ago

0.1.41

8 years ago

0.1.40

8 years ago

0.1.39

8 years ago

0.1.38

8 years ago

0.1.37

8 years ago

0.1.36

8 years ago

0.1.35

8 years ago

0.1.34

8 years ago

0.1.32

8 years ago

0.1.30

8 years ago

0.1.29

8 years ago

0.1.28

8 years ago

0.1.27

8 years ago

0.1.26

8 years ago

0.1.25

8 years ago

0.1.24

8 years ago

0.1.23

8 years ago

0.1.22

8 years ago

0.1.21

8 years ago

0.1.20

8 years ago

0.1.19

8 years ago

0.1.18

8 years ago

0.1.17

8 years ago

0.1.16

8 years ago

0.1.15

8 years ago

0.1.14

8 years ago

0.1.13

8 years ago

0.1.12

8 years ago

0.1.11

8 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.95

8 years ago

0.0.93

8 years ago

0.0.92

8 years ago

0.0.91

8 years ago

0.0.81

8 years ago

0.0.78

8 years ago

0.0.77

8 years ago

0.0.76

8 years ago

0.0.70

8 years ago

0.0.69

8 years ago

0.0.68

8 years ago

0.0.67

8 years ago

0.0.66

8 years ago

0.0.65

8 years ago

0.0.64

8 years ago

0.0.63

8 years ago

0.0.62

8 years ago

0.0.61

8 years ago

0.0.60

8 years ago

0.0.59

8 years ago

0.0.58

8 years ago

0.0.57

8 years ago

0.0.56

8 years ago

0.0.55

8 years ago

0.0.54

8 years ago

0.0.53

8 years ago

0.0.49

8 years ago

0.0.48

8 years ago

0.0.47

8 years ago

0.0.46

8 years ago

0.0.44

8 years ago

0.0.43

8 years ago

0.0.42

8 years ago

0.0.41

8 years ago

0.0.40

8 years ago

0.0.38

8 years ago

0.0.37

8 years ago

0.0.36

8 years ago

0.0.35

8 years ago

0.0.34

8 years ago

0.0.33

8 years ago

0.0.32

8 years ago

0.0.31

8 years ago

0.0.30

8 years ago

0.0.29

8 years ago

0.0.28

8 years ago

0.0.27

8 years ago

0.0.25

8 years ago

0.0.24

8 years ago

0.0.23

8 years ago

0.0.22

8 years ago

0.0.21

8 years ago

0.0.19

8 years ago

0.0.18

8 years ago

0.0.17

8 years ago

0.0.16

8 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago