1.1.1 • Published 2 years ago
h8-restriction v1.1.1
Installation:
$ npm install h8-restriction -D
Usage:
index.js
function myFunction() {
let arrayOfNumbers = [1, 2, 3, 4, 5]
return arrayOfNumbers.map(el => el * 2) // line number 3
}
checkRestriction.js
const Restriction = require('h8-restriction')
// checking index.js script for restriction rules
// init
const checkRestriction = new Restriction('index.js')
// promise
checkRestriction.readCode().then(result => console.log(result)) // arrayOfNumbers.map(el => el * 2) : 3
// async / await
async function checkStudentRestriction() {
const result = await checkRestriction.readCode()
return result // arrayOfNumbers.map(el => el * 2) : 3
}
js/index.js
function myFunction() {
let arrayOfNumbers = [1, 2, 3, 4, 5]
return arrayOfNumbers.map(el => el * 2) // line number 3
}
src/checkRestriction.js
const checkRestriction = new Restriction('../js/index.js')
checkRestriction.readCode().then(result => console.log(result)) // arrayOfNumbers.map(el => el * 2) : 3
It will return null (if it didn't found) or string (line of code and line number) value
This package will detect all of following function below (default):
.map()
.reduce()
.filter()
.indexOf()
.toLocaleString()
.lastIndexOf()
.reverse()
.reduceRight()
.includes()
.flat()
.flatMap()
.find()
.findIndex()
.fill()
.every()
.copyWithin()
.entries()
.of()
new Set()
You can add new syntax to the restriction rules:
checkRestriction.rules = ['concat', 'split', 'ceil', 'min'] // now package will check the concat and split syntax too
checkRestriction.readCode().then(result => console.log(result))
To remove your syntax from restriction rules:
checkRestriction.popRules = ['map', 'filter'] // now package will check the concat and split syntax too
checkRestriction.readCode().then(result => console.log(result))