@pakal/safify
v0.2.1
Published
Safify is package from Pakal library
Downloads
12
Maintainers
Readme
@pakal/safify
Safify is package from Pakal library
Install
$ yarn add @pakal/safify
Or
$ npm install --save @pakal/safify
Use
Module
import {
default as safify
} from '@pakal/safify';
Browser
<script src="https://unpkg.com/@pakal/safify/bundle.umd.min.js"></script>
let {
safify
} = _;
Examples
let hasOwnProperty = safify(Object.prototype.hasOwnProperty, false);
hasOwnProperty.call({foo: 'bar'}, 'foo') // => false
hasOwnProperty.call(null, 'foo') // => false
function get(object: object, key: PropertyKey): any | undefined {
return object[key];
}
let safeGet = safify(get, undefined);
safeGet([1, 2, 3], 0); // => 1
safeGet([], 0); // => undefined
safeGet(null, 0); // => undefined
License
Copyright © Yisrael Eliev, Licensed under the MIT license.