0.1.2 • Published 5 years ago

safer-function v0.1.2

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

safer-function

Build Status Coverage Status WebReflection status

Function traps for bind, call, and apply.

Please ensure this module, or any dependent of it, is included before any other or, at least, before any polyfill, to grant reliability.

import {bind, call, apply} from 'safer-function';
const {bind, call, apply} = require('./');

// basic usage
const {toString} = {};
call(toString, 'any object');

const {fromCharCode} = String;
call(fromCharCode, String, 104, 101, 108, 108, 111);
apply(fromCharCode, String, [104, 101, 108, 108, 111]);

// secured bound usage
const fromCharsCall = bind(fromCharCode, String);
fromCharsCall(104, 101, 108, 108, 111);

const fromCharsApply = bind(apply, call, fromCharCode, String);
fromCharsApply([104, 101, 108, 108, 111]);