Blame view
node_modules/eslint/lib/util.js
1.59 KB
c39994410
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
/** * @fileoverview Common utilities. */ "use strict"; //------------------------------------------------------------------------------ // Constants //------------------------------------------------------------------------------ var PLUGIN_NAME_PREFIX = "eslint-plugin-", NAMESPACE_REGEX = /^@.*\//i; //------------------------------------------------------------------------------ // Public Interface //------------------------------------------------------------------------------ /** * Removes the prefix `eslint-plugin-` from a plugin name. * @param {string} pluginName The name of the plugin which may have the prefix. * @returns {string} The name of the plugin without prefix. */ function removePluginPrefix(pluginName) { return pluginName.indexOf(PLUGIN_NAME_PREFIX) === 0 ? pluginName.substring(PLUGIN_NAME_PREFIX.length) : pluginName; } /** * @param {string} pluginName The name of the plugin which may have the prefix. * @returns {string} The name of the plugins namepace if it has one. */ function getNamespace(pluginName) { return pluginName.match(NAMESPACE_REGEX) ? pluginName.match(NAMESPACE_REGEX)[0] : ""; } /** * Removes the namespace from a plugin name. * @param {string} pluginName The name of the plugin which may have the prefix. * @returns {string} The name of the plugin without the namespace. */ function removeNameSpace(pluginName) { return pluginName.replace(NAMESPACE_REGEX, ""); } module.exports = { removePluginPrefix: removePluginPrefix, getNamespace: getNamespace, removeNameSpace: removeNameSpace, "PLUGIN_NAME_PREFIX": PLUGIN_NAME_PREFIX }; |