Js generating function parameters

there are a batch of statements to be written as follows (koa routing configuration), and the form is fixed as follows

router.get("/pattern", api.getPattern)
router.post("/pattern", api.setPattern)
router.get("/road", api.getRoad)
router.post("/road", api.setRoad)
......

if you want to generate this large number of statements quickly, how to deal with it

Mar.01,2021

What about the

variable?

A for loop is done


function firstUpperCase(str) {
    return str.toLowerCase().replace(/( |^)[a-z]/g, (l) => l.toUpperCase());
}

function add(name) {
    ['post', 'get'].forEach(m => {
        router[m](`/${name}`, api[m + firstUpperCase(name)])
    })
}

add('pattern')
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4456a-44aab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4456a-44aab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?