New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

obsify

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

obsify

Observableify a callback-style function

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

obsify Build Status

Observableify a callback-style function

Install

$ npm install --save obsify

Usage

const fs = require('fs');
const obsify = require('obsify');

obsify(fs.readFile)('package.json', 'utf8')
	.map(data => JSON.parse(data))
	.subscribe(data => {
		console.log(data.name);
		//=> 'obsify'
	});

// or observableify all methods in a module

obsify(fs).readFile('package.json', 'utf8')
	.map(data => JSON.parse(data))
	.subscribe(data => {
		console.log(data.name);
		//=> 'obsify'
	});

API

obsify(input, [options])

input

Type: function, object

Callback-style function or module whose methods you want to observableify.

options

include

Type: array of (string|regex)

Methods in a module to observableify. Remaining methods will be left untouched.

exclude

Type: array of (string|regex)
Default: [/.+Sync$/]

Methods in a module not to observableify. Methods with names ending with 'Sync' are excluded by default.

excludeMain

Type: boolean
Default: false

By default, if given module is a function itself, this function will be observableified. Turn this option on if you want to observableify only methods of the module.

const obsify = require('obsify');

function fn() {
    return true;
}

fn.method = (data, callback) => {
    setImmediate(() => {
        callback(data, null);
    });
};

// observableify methods but not fn()
const observableFn = obsify(fn, {excludeMain: true});

if (observableFn()) {
    observableFn.method('hi').subscribe(data => {
        console.log(data);
    });
}

License

MIT © Sam Verschueren

Keywords

observable

FAQs

Package last updated on 17 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts