UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

39 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rankName = rankName; /** * Every rule beyond the match itself, as `points` and when they apply. A list rather than a run of * conditions, so a rule can be read, weighed against its neighbours, or added without touching the rest. */ const Adjustments = [ /* what was typed, exactly, always comes first; the same spelling in another case comes next */ [1200, ({ name, needle }) => name === needle], [900, ({ name, needle }) => name !== needle && name.toLowerCase() === needle.toLowerCase()], /* a real function from base R is what a reader usually means; a lone symbol almost never is */ [40, ({ name, baseR }) => baseR === true && name.length >= 3], [-20, ({ variable }) => variable === true], [-40, ({ name }) => name.length < 3], /* `names<-` is the replacement form of `names`, and nobody reaches for it first */ [-35, ({ name }) => name.endsWith('<-')], [-45, ({ name, needle }) => name.includes('.') && !needle.includes('.')], /* `base` itself before the packages that merely ship with R */ [20, ({ base }) => base === true], /* a name flowR recognises outranks a closer spelling it knows nothing about: typing `plot` should offer `ggplot` before `plotH`, because one of them is a function people actually call */ [500, ({ known }) => known === true], [-30, ({ s3 }) => s3 === true], /* operators, punctuation and SHOUTING names are rarely what someone is looking for */ [-60, ({ name }) => /^%.*%$/.test(name) || /^[^\w.]/.test(name)], [-30, ({ name, needle }) => name === name.toUpperCase() && /[A-Z]/.test(name) && name !== needle], [-400, ({ name }) => name.startsWith('.')] ]; /** The points {@link NameRankInput} earns, higher being offered first. */ function rankName(of) { const { name, needle, rank = 0, downloads = 0 } = of; /* how well it matches comes first, then how short it is; popularity only settles what is left. Length only matters against something typed: with an empty box it would rank `AIC` above `mean` */ const match = -rank * 150 - (needle ? name.length * 12 : 0) + Math.min(Math.log10(downloads + 10), 8) * (needle ? 4 : 12); return Adjustments.reduce((points, [worth, when]) => when(of) ? points + worth : points, match); } //# sourceMappingURL=name-rank.js.map