util-ex
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

util-ex Build Status npm downloads license

Enhanced utils

This package modifies and enhances the standard util from node.js

API

Full API Documents is here: Docs

newFunction

newFunction(name, arguments, body[, scope[, values]])
newFunction(functionString[, scope[, values]])

create a function via string.

newFunction = require('util-ex/lib/new-function')

var fn = newFunction('yourFuncName', ['arg1', 'arg2'], 'return log(arg1+arg2);', {log:console.log})
newFunction('function yourFuncName(){}')
newFunction('function yourFuncName(arg1, arg2){return log(arg1+arg2);}', {log:console.log})
newFunction('function yourFuncName(arg1, arg2){return log(arg1+arg2);}', ['log'], [console.log])

//fn.toString() is :
/*
 "function yourFuncName(arg1, arg2) {
    return log(arg1+arg2);
 }"
*/

defineProperty

defineProperty(object, key, value[, aOptions])

Define a property on the object. move to inherits-ex package.

usage

const defineProperty = require('util-ex/lib/defineProperty')

let propValue = ''
const obj = {}

defineProperty(obj, 'prop', 'simpleValue')
defineProperty(obj, 'prop', undefined, {
  get() {return propValue}
  set(value) {propValue = value}
})

Package Sidebar

Install

npm i util-ex

Weekly Downloads

13,018

Version

1.0.3

License

MIT

Unpacked Size

182 kB

Total Files

154

Last publish

Collaborators

  • riceball