A utility to check if a JavaScript function is pure.
npm install is-function-pureis-function-pure is a JavaScript utility for detecting if function is pure.
```
npm install is-function-pure
Input: A string containing a single JavaScript function.
Output: A boolean indicating whether the function is pure.
`
const { isPure } = require('is-function-pure');
const pureFunction =
function multiply(a, b) {
return a * b;
};
console.log(isPure(pureFunction)); // Output: true
`
Input: A string containing JavaScript code.
Output: An object with pure and impure arrays.
`
const { separate } = require('is-function-pure');
const code =
const x = 5;
function add(a, b) {
return a + b;
}
function impure(a) {
return a + x;
};
const result = separate(code);
console.log('Pure Functions:', result.pure);
console.log('Impure Functions:', result.impure);
`
1. has references to outside scopes
2. uses Date() or Math.random()
3. uses this
4. does not have return statement
More about what is considered pure or not you can read in test cases:
https://github.com/senad87/is-function-pure/blob/main/tests/main-test.js
https://github.com/senad87/is-function-pure/blob/main/tests/purity-detector-test.js
```
npm run test
Love this project? ❤️
Support its development by becoming a sponsor.



Any amount is greatly appreciated! 🌟