# common-a2dev

> gather sometimes need.

Latest version **0.1.3** (published 2018-03-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install common-a2dev
pnpm add common-a2dev
yarn add common-a2dev
bun add common-a2dev
```

## 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.3 |
| Published | 2018-03-21 |
| First published | 2017-11-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | awisu2 |

## Links

- npm: https://www.npmjs.com/package/common-a2dev
- Repository: https://github.com/awisu2/js-common-a2dev
- Homepage: https://github.com/awisu2/js-common-a2dev#readme
- Issues: https://github.com/awisu2/js-common-a2dev/issues
- npm.io page: https://npm.io/package/common-a2dev

## Recent versions

- 0.1.3 (latest) — 2018-03-21
- 0.1.2 — 2018-03-17
- 0.1.1 — 2018-03-17
- 0.0.34 — 2017-12-23
- 0.0.33 — 2017-12-17
- 0.0.32 — 2017-12-16
- 0.0.31 — 2017-12-16
- 0.0.30 — 2017-12-03
- 0.0.29 — 2017-12-03
- 0.0.28 — 2017-12-03
- 0.0.27 — 2017-12-03
- 0.0.26 — 2017-11-26
- 0.0.25 — 2017-11-26
- 0.0.24 — 2017-11-25
- 0.0.23 — 2017-11-25
- … 22 more at https://npm.io/package/common-a2dev/versions

## README

# common-a2dev

gather sometimes need.

# usage

```js
var common = require("common-a2dev")

let v = []
if (common.isArray(v)) {
  console.log("it's array")
} else {
  console.log("it's not array")
}
```

# methods

##  existsArg (v)

check args isExists

```js
common.existsArg(undefined) // false
common.existsArg(1) // true
common.existsArg(null) // true
```

## canNumber (v)

check value it's can change number

```js
common.canNumber (1) // true
common.canNumber ("1") // true
common.canNumber ("a") // false
common.canNumber ("1a") // false
```

## hasDataObject (v)

check value it's false or when value is object not have data

```js
common.hasDataObject ({}) // false
common.hasDataObject ([]) // false
common.hasDataObject ([0]) // true
common.hasDataObject () // false
common.hasDataObject (0) // false
```

## valueObject (object, key, def)

get value from object

```js
common.valueObject ({a: 1}, "a", 2) // 1
common.valueObject ({a: 1}, "b", 2) // 2
```

## copyObject (object)

value copy object

```js
var obj1 = {a: 1}
var obj2 = common.copyObject (obj1) // 1
obj2.a = 2

console.log(obj1) // {a: 1}
console.log(obj2) // {a: 2}
```

## matchUrl (str, options = {})

get urls by string

```js
common.matchUrl ("http://exsample.com is url. second url is http://exsample2.com") // ["http://exsample.com", "http://exsample2.com"]
```

### options

- isDeleteEscape: boolean
  - if it's true. delete escape string.

## fillObject (obj, sample, options = {})

fill data by sample

```js
var obj = {a: 1}
var options = {
  isPrune: false
}
var obj2 = common.fillObject (obj, {b: 2}, options) // {a: 1, b: 2}
```

### options

- isPrune: boolean
  - if it's true. run prneOjbect after fillObject

## pruneObject (obj, sample, options = {})

prune data from obj not exists sample value

```js
var obj = {a: 1, b: 2}
var options = {
  isPrune: false
}
var obj2 = common.pruneObject (obj, {b: 2}, options) // {b: 2}
```

## randomInt (min, max)

get randomInt

```js
common.randomInt(1, 5) // 1-5
```

## typeString (v)

get value type from class

```js
common.typeString(1) // '[object Number]'
common.typeString("1") // '[object String]'
common.typeString([]) // '[object Array]'
common.typeString({}) // '[object Object]'
```

## isObject (v)

check value is object corectly

```js
common.isObject(1) // false
common.isObject("1") // false
common.isObject(null) // false
common.isObject([]) // false
common.isObject({}) // true
```

## isArray (v)

check value is object corectly

```js
common.isArray(1) // false
common.isArray("1") // false
common.isArray(null) // false
common.isArray([]) // true
common.isArray({}) // false
```

## isObjectArray (v)

check value is object or array. if it's null return is false.

```js
common.isObjectArray(1) // false
common.isObjectArray("1") // false
common.isObjectArray(null) // false
common.isObjectArray([]) // true
common.isObjectArray({}) // true
```

## getArgumentNode ()

get node binary path currentry run.

```js
common.getArgumentNode() // '/usr/local/Cellar/node/8.1.2/bin/node'
```

**NOTE**: please use only when cli.

## getArgumentCurrent ()

get node script path currentry run.

```js
common.getArgumentCurrent() // '/path/to/current/${script.js}'
```

**NOTE**: please use only when cli.

## getArgumentValue (index)

get value from argument.

```bash
node sample.js 1 2 3
```

```js
common.getArgumentValue(0) // 1
common.getArgumentValue(2) // 3
```

## addNodePathEnv (path)

add node path. for Environment

```js
common.addNodePathEnv("/path/to/node") // NODE_PATH: "${NODE_PATH};/path/to/node"
```

## getMatches (values, pattern)

get match string from multi string by pattern.

```js
common.getMatches(["abcdefgabcxyz", "hijxyz"], /cd/) // [ 'cd' ]
common.getMatches(["abcdefgabcxyz", "hijxyz"], /xy/) // [ 'xy', 'xy' ]
common.getMatches(["abcdefgabcxyz", "hijxyz"], /[a-z]{2}/) // [ 'ab', 'hi' ]
common.getMatches(["abcdefgabcxyz", "hijxyz"], /[a-z]{2}/g) // [ 'ab', 'cd', 'ef', 'ga', 'bc', 'xy', 'hi', 'jx', 'yz' ]
```

## getMaxLengthStr (strings)

get max length from strings

```js
common.getMaxLengthStr(["1", "333", "22"]) // 3
```

## fillStr (str, length, fill = '0')

fill string fill

```js
common.fillStr(123, 6) // '00123'
common.fillStr(123, 2) // '23'
common.fillStr(123, 6, "ZY") // 'ZYZ123'
common.fillStr("abc", 7, "ZY") // 'ZYZYabc'
```

**NOTE**: when fill's value is multi. stacking from the front.

## betweenStr (str, prefix, suffix, options = {})

get string btween prefix and suffix

```js
common.betweenStr("abcdefghijklmn", "cd", "kl") // 'efghij'
common.betweenStr("abcdefghijklmn", "ZZ", "ZZ") // ''
common.betweenStr("abcdefghijklmn", "cd", "kl", {isDetail: true}) // [ 'cdefghijkl', 'efghij', index: 2, input: 'abcdefghijklmn' ]
```

### options

- isDetail: boolean
  - if it's true. return match object.


## escapeRegStr (str)

escape string for regExp

## disallowStringFileName ()

get disallow strings for filename.

```js
common.disallowStringFileName () // [ '\\', '/', ':', '*', '?', '"', '<', '>', '|' ]
```

## replaceDisallowStringFileName (str, replace = '')

replace disallow string from string for filename of filesystem.

```js
common.disallowStringFileName () // [ '\\', '/', ':', '*', '?', '"', '<', '>', '|' ]
```


## Date.format

```js
var d = new Date
d.format('YYYY-MM-DDTHH:mm:SS') // '2018-03-17T13:54:38'
```

**NOTE**: automaticaly set prototype

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