# conf-validator

> configuration validator

Latest version **1.1.3** (published 2020-12-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install conf-validator
pnpm add conf-validator
yarn add conf-validator
bun add conf-validator
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2020-12-15 |
| First published | 2019-07-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 162.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Thanakhan Iaocharoen |
| Maintainers | khunbankz |

## Links

- npm: https://www.npmjs.com/package/conf-validator
- npm.io page: https://npm.io/package/conf-validator

## Dependencies (1)

- [ajv](https://npm.io/package/ajv.md) ^6.12.3

## Recent versions

- 1.1.3 (latest) — 2020-12-15
- 1.1.2 — 2020-07-07
- 1.1.1 — 2020-03-04
- 1.1.0 — 2019-11-27
- 1.0.11 — 2019-10-15
- 1.0.10 — 2019-09-27
- 1.0.9 — 2019-09-27
- 1.0.8 — 2019-09-27
- 1.0.7 — 2019-09-27
- 1.0.6 — 2019-09-24
- 1.0.5 — 2019-09-10
- 1.0.4 — 2019-09-09
- 1.0.3 — 2019-09-03
- 1.0.2 — 2019-08-14
- 1.0.1 — 2019-08-14
- … 1 more at https://npm.io/package/conf-validator/versions

## README

# configurationValidator

## Example
```js 
//require package
var validate = require('conf-validator')
//create schema that you want to validate
let schema = [{
	name: "name", // ชื่อที่จะแสดงใน log กรณี validate ไม่ผ่าน
	value: object, // object ที่ต้องการ validate
	schema: [{
		config_path: "" //path ที่เป็น array ระบุ/ไม่ระบุ index ก็ได้ (ถ้าไม่ระบุต้องวนทุก array)ต้องมีพารามิเตอร์ตัวนี้ (M)
		min: int //type string or numberic or alphanumberic == length, int or double==value  มีหรือไม่มีพารามิเตอร์ตัวนี้ (O)
		max: int //type string or numberic or alphanumberic == length, int or double==value มีหรือไม่มีพารามิเตอร์ตัวนี้ (O)
		eq: int //type string or numberic or alphanumberic == length, int or double==value มีหรือไม่มีพารามิเตอร์ตัวนี้ (O)
		array: $value //true/false,    //default == false
		required_attr: $value //true/false, true == ต้องมี attribute   //default == true
		required_val: $value //true/false, true == ต้องมี value มา ห้ามว่าง //default == true
		type: //numberic, alphanumberic, integer, string, boolean , regexp , condition , double , object 
		regexp: "[1-9]", //ถ้า type เป็น regexp จะต้องมีพารามิเตอร์นี้
		condition: fn( object, key, value) //ถ้า type เป็น condition จะต้องมีพารามิเตอร์นี้
	}]
}]

//call function validator 
let isCorrect = validate.validator(schema) // return boolean
```


## ตัวอย่าง  1
``` js
//object ที่ต้องการ validate
let conf1 = {
	"apps": [{
		"script": "index.js",
		"name": "cauldron",
		"env": {
			"node_name": "cauldron",
			"app_host": "0.0.0.0",
			"app_port": "3000",
			"use_https": false
		}
	}]
}

//schema สำหรับ validate object
const schema = [{
	"name": "pm2.json",
	"value": conf1,
	schema: [{
		"config_path": "apps[0].script",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "string"
	}, {
		"config_path": "apps[0].name",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "string"
	}, {
		"config_path": "apps[0].env",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "object"
	} , {
		"config_path": "apps[0].env.node_name",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "string"
	}, {
		"config_path": "apps[0].env.app_host",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "string"
	}, {
		"config_path": "apps[0].env.app_port",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "string",
		"eq" : 4
	}, {
		"config_path": "apps[0].env.use_https",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "boolean"
	}]
}]

var validate = require('configurationValidator')
let isCorrect = validate.validator(schema) // return boolean
```

## ตัวอย่าง 2
``` js
let conf2 = {
	"apps": [{
		"script": "index.js",
		"name": "cauldron",
		"env": {
			"node_name": "cauldron",
			"app_host": "0.0.0.0",
			"app_port": 3000,
			"use_https": false
		}
	}]
}

const schema = [{
	"name": "pm2.json",
	"value": conf2,
	schema: [{
		"config_path": "apps[0].script",
	}, {
		"config_path": "apps[0].name",
	}, {
		"config_path": "apps[0].env",
		"type": "object"
	}, {
		"config_path": "apps[0].env.node_name",
	}, {
		"config_path": "apps[0].env.app_host",
	}, {
		"config_path": "apps[0].env.app_port",
		"type": "integer"
	}, {
		"config_path": "apps[0].env.use_https",
		"type": "boolean"
	}]
}]

var validate = require('configurationValidator')
let isCorrect = validate.validator(schema, function (txt) { // callback return text log
	console.log(txt)
})
```

## ตัวอย่าง 3
``` js
let conf3 = {
	"apps": [{
		"script": "index.js",
		"name": "cauldron",
		"env": {
			"node_name": "cauldron",
			"app_host": "0.0.0.0",
			"app_port": "3000",
			"use_https": false
		}
	},
{
		"script": "index.js",
		"name": "validate",
		"env": {
			"node_name": "validate",
			"app_host": "0.0.0.0",
			"app_port": "4000",
			"use_https": true
		}
	}]
}

const schema = [{
	"name": "pm2.json",
	"value": conf3,
	schema: [{
		"config_path": "apps[].script",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "string"
	}, {
		"config_path": "apps[].name",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "string"
	}, {
		"config_path": "apps[].env",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "object"
	} , {
		"config_path": "apps[].env.node_name",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "string"
	}, {
		"config_path": "apps[].env.app_host",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "string"
	}, {
		"config_path": "apps[].env.app_port",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "regexp",
		"regexp" : "\\d{4}"
	}, {
		"config_path": "apps[].env.use_https",
		"array": false,
		"required_attr": true,
		"required_val": true,
		"type": "boolean"
	}]
}]

var validate = require('configurationValidator')
let isCorrect = validate.validator(schema)
```


> history
1.0.0 init version
1.0.1 add function buildPM2ENVObj()
1.0.2 fixed function buildPM2ENVObj()
1.0.3 change readme
1.0.4 fixed buildPM2ENVObj() build log => commonLog
1.0.8 fixed isRequireAttr()
1.0.9,1.0.10 validate ip (domain & ip & wildcard)
1.0.11 fixed bug display error
1.1.1 add redis value to conn_type (type.json)
1.1.1 add dependencies (ajv)
1.1.3 add conn_type smtp

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