lib/Language/Helpers/methodMatch.js
function methodMatch(part) {
    let maxMatch = null
    let maxMatchCount = 0

    // Go through each mapper and check if the name matches. Then, take the highest match to avoid matching
    // 'any', if 'any character' was given, and so on.
    Object.keys(mapper).forEach((key) => {
        const regex = new RegExp(`^(${key.replace(' ', ') (')})`, 'i')
        const matches = part.match(regex)

        const count = matches ? matches.length : 0

        if (count > maxMatchCount) {
            maxMatchCount = count
            maxMatch = key
        }
    })

    if (maxMatch) {
        // We've got a match. Create the desired object and populate it.
        const item = mapper[maxMatch]
        return new item['class'](maxMatch, item.method, buildQuery)
    }

    throw new SyntaxException(`Invalid method: ${part}`)
}
function methodMatch(part) {
    let maxMatch = null
    let maxMatchCount = 0

    // Go through each mapper and check if the name matches. Then, take the highest match to avoid matching
    // 'any', if 'any character' was given, and so on.
    Object.keys(mapper).forEach((key) => {
        const regex = new RegExp(`^(${key.replace(' ', ') (')})`, 'i')
        const matches = part.match(regex)

        const count = matches ? matches.length : 0

        if (count > maxMatchCount) {
            maxMatchCount = count
            maxMatch = key
        }
    })

    if (maxMatch) {
        // We've got a match. Create the desired object and populate it.
        const item = mapper[maxMatch]
        return new item['class'](maxMatch, item.method, buildQuery)
    }

    throw new SyntaxException(`Invalid method: ${part}`)
}
function methodMatch ( part ) { let maxMatch = null let maxMatchCount = 0 // Go through each mapper and check if the name matches. Then, take the highest match to avoid matching // 'any', if 'any character' was given, and so on. Object . keys ( mapper ) . forEach ( ( key ) => { const regex = new RegExp ( ` ${ key . replace ( ' ' , ') (' ) } ` , 'i' ) const matches = part . match ( regex ) const count = matches ? matches . length : 0 if ( count > maxMatchCount ) { maxMatchCount = count maxMatch = key } } ) if ( maxMatch ) { // We've got a match. Create the desired object and populate it. const item = mapper [ maxMatch ] return new item [ 'class' ] ( maxMatch , item . method , buildQuery ) } throw new SyntaxException ( ` ${ part } ` ) }
Match a string part to a method. Please note that the string must start with a method.

@param {string} part
@throws {SyntaxException} If no method was found, a SyntaxException will be thrown.
@return {method}
Match a string part to a method . Please note that the string must start with a method .