Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wall-wxk/function-sniffer
js方法嗅探器
https://github.com/wall-wxk/function-sniffer
Last synced: 16 days ago
JSON representation
js方法嗅探器
- Host: GitHub
- URL: https://github.com/wall-wxk/function-sniffer
- Owner: wall-wxk
- License: mit
- Created: 2017-01-16T15:52:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T06:26:59.000Z (almost 2 years ago)
- Last Synced: 2024-10-19T22:35:30.327Z (25 days ago)
- Language: JavaScript
- Size: 1.3 MB
- Stars: 10
- Watchers: 1
- Forks: 5
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# [![CircleCI](https://img.shields.io/circleci/build/github/wall-wxk/function-sniffer/master)](https://circleci.com/gh/wall-wxk/function-sniffer/tree/master) [![Coverage Status](https://coveralls.io/repos/github/wall-wxk/function-sniffer/badge.svg?branch=master)](https://coveralls.io/github/wall-wxk/function-sniffer?branch=master) [![NPM version](https://img.shields.io/npm/v/function-sniffer.svg)](https://www.npmjs.com/package/function-sniffer) [![download](https://img.shields.io/npm/dm/function-sniffer)](https://www.npmjs.com/package/function-sniffer) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/wall-wxk/function-sniffer/blob/master/LICENSE)
## Features
- Sniffer function can or can't run.
- can do lazy run until function is loaded.## Environment Support
- Modern browsers and Internet Explorer 6+
| [](http://godban.github.io/browsers-support-badges/)IE / Edge | [](http://godban.github.io/browsers-support-badges/)Firefox | [](http://godban.github.io/browsers-support-badges/)Chrome | [](http://godban.github.io/browsers-support-badges/)Safari | [](http://godban.github.io/browsers-support-badges/)Opera | [](http://godban.github.io/browsers-support-badges/)Electron |
| --- | --- | --- | --- | --- | --- |
| IE6+, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions | last 2 versions |## Usage
Using npm
```bash
npm install --save function-sniffer
```node environment:
```js
var Sniffer = require('function-sniffer');
```webpack or similar environment:
```js
import Sniffer from 'function-sniffer';
```requirejs environment:
```js
requirejs(['node_modules/function-sniffer/dist/function-sniffer.cjs.js'], function (base) {
// do something...
})
```browser environment:
```html```
## Example
This is a Object `Tool` has a function `do`.
// tool.js
```javascript
(function(Tool, undefined){
Tool.do = function(thing){
console.log('try to do '+ thing);
}
})(window.Tool || (window.Tool = {});
```Now, `Sniffer.run` can execute function just like `Tool.do`.
- **Sniffer.run**
- **base** `default: window, base is not required, if object is base on window.`
- **name** `execute `base.name` function. is required.`
- **prompt** `prompting when function can't be found and execute. not required.`
- **showPromptFn** `custom prompt function. default is alert. not required.`
- **subscribe** `if you want to lazy run function which is not exist now.Sniffer memory it.When function loaded, try Sniffer.trigger to run it. not required.````javascript
import Sniffer from 'function-sniffer';
Sniffer.run({
name: 'Tool.do',
prompt: 'Tool.do is not exist.',
showPromptFn: (str)=>{ console.log(str);},
subscribe: true
});
````Sniffer.trigger` can run the memory list of function.
- **Sniffer.trigger**
- **base** `default: window, base is not required, if object is base on window.`
- **name** `execute `base.name` function. is required.````javascript
import Sniffer from 'function-sniffer';
Sniffer.run({
name: 'Tool.walk',
subscribe: true
});// walk() is not exist in Tool.And Sniffer memory it, Because `subscribe:true`.
Tool.walk = function(person){
console.log(person + ' is walking.');
}// walk loaded.And trigger to run it.
Sniffer.trigger({
base: Tool,
name: 'walk'
}, 'leon')// => leon is walking.
```## License
MIT