# ninjs-lodash

> lodash wrapper + utils

Latest version **0.1.98** (published 2017-01-11) · AGPL-1.0 license · 0 weekly downloads

## Install

```sh
npm install ninjs-lodash
pnpm add ninjs-lodash
yarn add ninjs-lodash
bun add ninjs-lodash
```

Provides the command `_`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.98 |
| Published | 2017-01-11 |
| First published | 2016-10-07 |
| Weekly downloads | 0 |
| License | AGPL-1.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.6 |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Stuart J. MacKenzie |
| Maintainers | smack |
| Keywords | ninjs, lodash |

## Links

- npm: https://www.npmjs.com/package/ninjs-lodash
- Repository: https://github.com/snapptop/ninjs-lodash
- Homepage: git+https://github.com/snapptop/ninjs-lodash.git#readme
- Issues: https://github.com/snapptop/ninjs-lodash/issues
- npm.io page: https://npm.io/package/ninjs-lodash

## Dependencies (6)

- [glob](https://npm.io/package/glob.md) ^7.1.1
- [async](https://npm.io/package/async.md) ^2.1.4
- [lodash](https://npm.io/package/lodash.md) ^4.17.3
- [moment](https://npm.io/package/moment.md) ^2.17.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^1.0.0
- [cli-color](https://npm.io/package/cli-color.md) ^1.1.0

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 0.1.98 (latest) — 2017-01-11
- 0.1.97 — 2017-01-04
- 0.1.96 — 2017-01-02
- 0.1.95 — 2017-01-02
- 0.1.94 — 2016-12-31
- 0.1.93 — 2016-12-21
- 0.1.92 — 2016-12-21
- 0.1.91 — 2016-12-21
- 0.1.89 — 2016-12-21
- 0.1.88 — 2016-12-21
- 0.1.87 — 2016-12-20
- 0.1.86 — 2016-12-19
- 0.1.85 — 2016-12-19
- 0.1.84 — 2016-12-19
- 0.1.83 — 2016-12-18
- … 151 more at https://npm.io/package/ninjs-lodash/versions

## README

# 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.

```json
{
  "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

```bash
npm install --save ninjs-lodash
```

### Import

import 'ninjs-lodash' (instead of 'lodash')

Now you can use existing lodash utils AND/OR ninjs mixins

```js
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

```js
_.$('keypath.to.list[3]')
```

---

## Scripts/Debugging

```json
{
  "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 scripts<br>Otherwise switches will not be passed to the spawned process created by 'npm run script' command

```bash
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*

```js
{
  // 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*

```js
{
  "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

```json
{
  "bin": { "ninjs-lodash" : "./bin/cli.js" },
  "cli": "set NODE_ENV=development && set DEBUG=* && node ./bin/cli.js"
}
```

> ./bin/cli.js

```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 ...

```bash
> npm run cli -- api.module.publish --name=ninjs-lodash
```

> Terminal * (Global) -> %cli-alias% keypath.something.method --switches --k=v ...

```bash
> ninjs-lodash api.module.publish --name=ninjs-lodash
```

> NOTE: args/switches after '--' proxied to spawned npm run-script process

---

## String

```js
_.bytes(num)        // returns formatted byte string
```

---

## Path

```js
_.path[*]           // require('path') + extras
_.path.name(src)
_.path.dir(src)
_.path.base(src)
_.path.isAbsolute(src)
```

---

## Url String

```js
_.url[*]            // require('url') + extras
```

---

## Plain Object

```js
_.acopy(...args)    // _.assign with no mutation
_.mcopy(...args)    // _.merge with no mutation
_.deepExtend(o, ob) // deep merge
```

---

## Array Object

```js
_.args(...args)     // returns flattened array of args, args, string, ....
```

---

## Async

```js
_.async[*]          // require('async')
_.fail(err, cb)     // callback(err)
_.done(result, cb)  // callback(null, result)
_.cb(callback)      // callback || function noop() {}
```

---

## File System

```js
_[*fs]              // common fs-extra assigned to _
_.fs[*]             //  _.fs = require('fs-extra')
```

---

&nbsp;

---
_Source: https://npm.io/package/ninjs-lodash · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
