# adenovo-utils

> util methods for adenovo

Latest version **0.0.7** (published 2018-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install adenovo-utils
pnpm add adenovo-utils
yarn add adenovo-utils
bun add adenovo-utils
```

## 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.0.7 |
| Published | 2018-09-07 |
| First published | 2018-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Cho-Ching Lu |
| Maintainers | chochinlu |
| Keywords | adenovo, util, log, logger, 身分證, 中華民國, idcard |

## Links

- npm: https://www.npmjs.com/package/adenovo-utils
- Repository: https://github.com/chochinlu/adenovo-utils
- Homepage: https://github.com/chochinlu/adenovo-utils#readme
- Issues: https://github.com/chochinlu/adenovo-utils/issues
- npm.io page: https://npm.io/package/adenovo-utils

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.0.7 (latest) — 2018-09-07
- 0.0.6 — 2018-09-06
- 0.0.5 — 2018-09-06
- 0.0.4 — 2018-09-04
- 0.0.3 — 2018-08-23
- 0.0.2 — 2018-08-23
- 0.0.1 — 2018-08-23

## README

# Adenovo utils

Util methods for [Adenovo](https://www.adenovo.com/),  maybe you can find what utils you want here.

- [Pid](#pid)
- [Basic log](#basic-log)
- [Functional utils](#functional-utils): pipe, pipeAsync, compose, composeAsync...
- [Object utils](#object-utils): check if object empty, remove empty values from object...

## Pid

中華民國身分證字號檢查與產生器, 基於[wiki](https://zh.wikipedia.org/wiki/%E4%B8%AD%E8%8F%AF%E6%B0%91%E5%9C%8B%E5%9C%8B%E6%B0%91%E8%BA%AB%E5%88%86%E8%AD%89#%E7%B7%A8%E8%99%9F%E8%A6%8F%E5%89%87)


``` js
const {checkPid, genPid} = require('adenovo-utils').pid;

const somePid = genPid(); //'B169298328'
const errorResult = checkPid('dsds'); // { result: false, msg: '身分證字號長度不正確' }

const okResult = checkPid('B169298328'); // { result: true }
```

## Basic log

``` js
const {debugLog} = require('adenovo-utils').log;

debugLog('for debug usage');  // [debug] for debug usage
```

### For ELK duration logs:

``` js
const {durationLog, startLog, endLog} = require('adenovo-utils').log;

const event = {foo: 'bar', hello: 'world'}; // your event object

durationLog('test')(event); // Lambda Event End: {"foo":"bar","hello":"world"}

startLog(event); // Lambda Event Start: {"foo":"bar","hello":"world"}

endLog(event); // Lambda Event End: {"foo":"bar","hello":"world"}
```

### For ELK action logs (basic)

``` js
const {actionLog} = require('adenovo-utils').log;

const event = {foo: 'bar', hello: 'world'};
const payload = {group: 'mygroup', method: 'paySomething', data: event}; // optional: memberId

actionLog('handler')('debug')(payload); // DEV,debug,handler,mygroup,paySomething,{"foo":"bar","hello":"world"}

```

### For ELK action logs (more specific)

Includes:
  - handlerLog(logLevel: string)(payload: object)
  - handlerLogDebug(payload)
  - handlerLogInfo
  - handlerLogWarning
  - handlerLogError
  - modelLog(logLevel: string)(payload: object)
  - modelLogDebug(payload)
  - modelLogInfo
  - modelLogWarning
  - modelLogError

For example:

``` js
const {handlerLog, modelLog, handlerLogDebug, modelLogWarning} = require('adenovo-utils').log;

const event = {foo: 'bar'};
const payload = {group: 'mygroup', method: 'paySomething', data: event};

handlerLog('hello')(payload); // DEV,hello,handler,mygroup,paySomething,{"foo":"bar"}
modelLog('world')(payload); // DEV,world,model,mygroup,paySomething,{"foo":"bar"}
handlerLogDebug(payload); // DEV,debug,handler,mygroup,paySomething,{"foo":"bar"}
modelLogWarning(payload); // DEV,warning,model,mygroup,paySomething,{"foo":"bar"}
```

### ELK action log payload wrapping

``` js
const {handlerLogInfo, getLogPayload} = require('adenovo-utils').log;

const FUNC_TITLE = 'xxxxPayment';
const logFuncPayload = getLogPayload(FUNC_TITLE);

// ...

const methodName = 'xxxPaymentCallback';
const logPayload = logFuncPayload(methodName);

// ...

const orderInfo = {foo: 'bar'};
const member_id = 1234;
handlerLogInfo(logPayload(orderInfo)(memberId));
```

## Functional utils

``` js
const {pipe, pipeAsync, compose, composeAsync} = require('adenovo-utils').functional;

const fn1 = a => a + 2;
const fn2 = a => a * 3;

const resp1 = pipe(fn1, fn2)(3); //  3 -> fn1 -> fn2 , result: 15

const resp2 = compose(fn1, fn2)(3); // 3 -> fn2 -> fn1, result: 11
```

`pipeAsync` and `composeAsync` are async pipe/compose version, you can chain your async functions !


## Object utils

`removeEmpty` will remove the null and undefined entries from an object (will not remove empty string value).

``` js
const {isEmpty, removeEmpty} = require('adenovo-utils').obj;

const obj1 = {};
const obj2 = {a: 1, b:2};

const result1 = isEmpty(obj1); // true
const result2 = isEmpty(obj2); // false

const obj3 =  {a:1, b: undefined, c: null, d: 1, e: ''};
const result3 = removeEmpty(a); // { a: 1, d: 1, e: '' }
```

a `{key: key}` translator:

``` js
const {keyMirror} = require('adenovo-utils').obj;

const arr1 = ['a', 'b'];
keyMirror(arr1);  //{ a: 'a', b: 'b'}

const arr2 = [1, 2];
keyMirror(arr2);  //{ '1': 1, '2': 1}
```

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