# get-safe-value

> A library of utility functions that can safely retrieve values

Latest version **1.7.0** (published 2021-05-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install get-safe-value
pnpm add get-safe-value
yarn add get-safe-value
bun add get-safe-value
```

## 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.7.0 |
| Published | 2021-05-11 |
| First published | 2020-07-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 24.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | huweiweb@126.com |
| Maintainers | huweicool |

## Links

- npm: https://www.npmjs.com/package/get-safe-value
- Repository: https://github.com/huweicool/get-safe-value
- Homepage: https://github.com/huweicool/get-safe-value#readme
- Issues: https://github.com/huweicool/get-safe-value/issues
- npm.io page: https://npm.io/package/get-safe-value

## Dependencies (4)

- [typescript](https://npm.io/package/typescript.md) ^4.2.3
- [validate-data-type](https://npm.io/package/validate-data-type.md) ^1.1.4
- [@rollup/plugin-typescript](https://npm.io/package/@rollup/plugin-typescript.md) ^8.2.0
- [rollup-plugin-typescript2](https://npm.io/package/rollup-plugin-typescript2.md) ^0.30.0

## Recent versions

- 1.7.0 (latest) — 2021-05-11
- 1.6.0 — 2021-05-11
- 1.5.0 — 2021-03-25
- 1.4.9 — 2021-03-25
- 1.4.8 — 2021-03-25
- 1.4.7 — 2021-03-25
- 1.4.6 — 2021-03-23
- 1.4.5 — 2020-11-17
- 1.4.3 — 2020-11-17
- 1.4.1 — 2020-11-16
- 1.4.0 — 2020-11-10
- 1.2.4 — 2020-08-16
- 1.2.3 — 2020-08-12
- 1.2.2 — 2020-08-10
- 1.2.1 — 2020-08-10
- … 18 more at https://npm.io/package/get-safe-value/versions

## README

[中文文档](https://github.com/huweicool/get-safe-value/blob/master/README-Chinese.md)

# get-safe-value

 In a secure way, a library of function tools for obtaining values of a particular data type.


## Install

Install with [npm](https://www.npmjs.com/package/get-safe-value)

```sh
  npm install get-safe-value
	yarn add get-safe-value
```


## Usage

```js
import { getString, getNumber, getBoolean, getObject, getArray, getFunction, getAny } from 'get-safe-value';
// or
// const { getString, getNumber, getBoolean, getObject, getArray, getFunction, getAny } =  require('get-safe-value');
const obj = {
	name: 'lucas',
	age: 30,
	brother: [
		{ 
			name: 'jack',
			age: 25,
		}
	],
	getName: ()=>{
		return this.name;
	},
}
// getString
console.log(getString(obj, "name")); // 'lucas'
console.log(getString(obj, "age")); // '30'  String array and Boolean, both call String constructor to String type
console.log(getString(obj, "helloWorld")); // ''
console.log(getString(obj, "brother[0].name")); // 'jack'
console.log(getString(obj, ["name", "brother[0].name"])); // ["lucas", "jack"]

//getNumber
console.log(getNumber(obj, "age")); //30
console.log(getNumber(obj, "name")); //0 Type mismatch default return Number：0 Number：0

//getBoolean
console.log(getBoolean({is: true}, "is")) // true
console.log(getBoolean({is: false}, "is")) // false
console.log(getBoolean({is: false}, "hello")) // false

//getObject
console.log(getObject(obj, "brother[0]")) // { name:'jack', age: 25 }
console.log(getObject(obj, "hello")) // {}

//getArray
console.log(getArray(obj, "brother")) // [{ name:'jack', age: 25 }]
console.log(getArray(obj, "name")) // []

//getFunction
console.log(getFunction(obj, "name")) // function(){}
console.log(getFunction(obj, "getName")) // function getName(){}

//getAny
console.log(getAny(obj, "name")) // 'lucas'
console.log(getAny(obj, "age")) // 30,
console.log(getAny(obj, "hello")) // undefined
```


## methods

| method | Return type |
| ------ | ------ |
| getString | String, Array |
| getNumber | Number, Array |
| getBoolean | Boolean, Array |
| getObject | Object, Array |
| getArray | Array |
| getFunction | Function, Array |
| getAny | Any, Array |


## Test
More examples to see the test
```sh
  npm test
```

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