Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dustinspecker/func-has-param
Check if function in file has parameter
https://github.com/dustinspecker/func-has-param
Last synced: 2 days ago
JSON representation
Check if function in file has parameter
- Host: GitHub
- URL: https://github.com/dustinspecker/func-has-param
- Owner: dustinspecker
- License: mit
- Created: 2015-07-12T02:02:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-31T21:39:35.000Z (over 7 years ago)
- Last Synced: 2024-10-07T05:09:55.988Z (about 1 month ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# func-has-param
[![NPM version](https://badge.fury.io/js/func-has-param.svg)](https://badge.fury.io/js/func-has-param) [![Build Status](https://travis-ci.org/dustinspecker/func-has-param.svg)](https://travis-ci.org/dustinspecker/func-has-param) [![Coverage Status](https://img.shields.io/coveralls/dustinspecker/func-has-param.svg)](https://coveralls.io/r/dustinspecker/func-has-param?branch=master)[![Code Climate](https://codeclimate.com/github/dustinspecker/func-has-param/badges/gpa.svg)](https://codeclimate.com/github/dustinspecker/func-has-param) [![Dependencies](https://david-dm.org/dustinspecker/func-has-param.svg)](https://david-dm.org/dustinspecker/func-has-param/#info=dependencies&view=table) [![DevDependencies](https://david-dm.org/dustinspecker/func-has-param/dev-status.svg)](https://david-dm.org/dustinspecker/func-has-param/#info=devDependencies&view=table)
> Check if function in file has parameter
## Install
```
npm install --save func-has-param
```## Usage
### ES2015 (ES6)
```javascript
import fs from 'fs';
import funcHasParam from 'func-has-param';// contents of awesome-js-file.js
/**
* function test(param) {}
*/
fs.readFile('awesome-js-file.js', 'utf8', (err, data) => {
funcHasParam(data, 'test', 'param');
// => truefuncHasParam(data, 'test', 'x');
// => false
});// contents of awesome-coffee-file.coffee
/**
* test = (param) -> {}
*/
fs.readFile('awesome-coffee-file.coffee', 'utf8', (err, data) => {
funcHasParam(data, 'test', 'param', {language: 'coffee'});
// => truefuncHasParam(data, 'test', 'x', {language: 'coffee'});
// => false
});// contents of awesome-ts-file.ts
/**
* function test (param: string): string {}
*/
fs.readFile('awesome-ts-file.ts', 'utf8', (err, data) => {
funcHasParam(data, 'test', 'param', {language: 'ts'});
// => truefuncHasParam(data, 'test', 'param', {language: 'ts', type: 'string'});
// => truefuncHasParam(data, 'test', 'param', {language: 'ts', type: 'int'});
// => falsefuncHasParam(data, 'test', 'x', {language: 'ts'});
// => false
});
```### ES5
```javascript
var fs = require('fs')
, funcHasParam = require('func-has-param');// contents of awesome-js-file.js
/**
* function test(param) {}
*/
fs.readFile('awesome-js-file.js', 'utf8', function (err, data) {
funcHasParam(data, 'test', 'param');
// => truefuncHasParam(data, 'test', 'x');
// => false
});// contents of awesome-coffee-file.coffee
/**
* test = (param) -> {}
*/
fs.readFileSync('awesome-coffee-file.coffee', 'utf8', function (err, data) {
funcHasParam(data, 'test', 'param', {language: 'coffee'});
// => truefuncHasParam(data, 'test', 'x', {language: 'coffee'});
// => false
});// contents of awesome-ts-file.ts
/**
* function test (param: string): string {}
*/
fs.readFileSync('awesome-ts-file.ts', 'utf8', function (err, data) {
funcHasParam(data, 'test', 'param', {language: 'ts'});
// => truefuncHasParam(data, 'test', 'param', {language: 'ts', type: 'string'});
// => truefuncHasParam(data, 'test', 'param', {language: 'ts', type: 'int'});
// => falsefuncHasParam(data, 'test', 'x', {language: 'ts'});
// => false
});
```## API
### funcHasParam(fileContents, functionName, parameterName, [options])
Returns a `boolean`.
#### fileContents
Type: `string`
File contents to be searched for `functionName` with `parameterName`.
#### functionName
Type: `string`
Function name to look for.
#### parameterName
Type: `string`
Parameter name to look for within function signature.
#### options
##### language
Type: `string`
Default: `js`
A string with the language of the file being inspected. Default option is `js` for JavaScript. Other possible options are `coffee` for CoffeeScript and `ts` for TypeScript.
##### regex
Type: `regex`
Custom regex to use. Must include a group.
##### type
Type: `string`
Only used when using language option with `ts` value. A string that's used to match the parameter type as well as the parameter name.
## LICENSE
MIT