mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Convert to atom doc
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
module.exports = {selectorMatchesAnyScope, matcherForSelector}
|
||||
|
||||
const _ = require('underscore-plus')
|
||||
const {isSubset} = require('underscore-plus')
|
||||
|
||||
/**
|
||||
* Parse a selector into parts. If already parsed, returns the selector
|
||||
* unmodified.
|
||||
*
|
||||
* @param {String|Array<String>} selector
|
||||
* @returns {Array<String>} selector parts
|
||||
*/
|
||||
// Private: Parse a selector into parts.
|
||||
// If already parsed, returns the selector unmodified.
|
||||
//
|
||||
// * `selector` a {String|Array<String>} specifying what to match
|
||||
// Returns selector parts, an {Array<String>}.
|
||||
function parse (selector) {
|
||||
return typeof selector === 'string'
|
||||
? selector.replace(/^\./, '').split('.')
|
||||
@@ -17,26 +15,23 @@ function parse (selector) {
|
||||
|
||||
const always = scope => true
|
||||
|
||||
/**
|
||||
* Return a matcher function for a selector.
|
||||
*
|
||||
* @param {String} selector
|
||||
* @returns {(scope: String) -> Boolean} a matcher function
|
||||
*/
|
||||
// Essential: Return a matcher function for a selector.
|
||||
//
|
||||
// * selector, a {String} selector
|
||||
// Returns {(scope: String) -> Boolean}, a matcher function returning
|
||||
// true iff the scope matches the selector.
|
||||
function matcherForSelector (selector) {
|
||||
const parts = parse(selector)
|
||||
return selector
|
||||
? scope => _.isSubset(parts, parse(scope))
|
||||
? scope => isSubset(parts, parse(scope))
|
||||
: always
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true iff the selector matches any provided scope.
|
||||
*
|
||||
* @param {String} selector
|
||||
* @param {Array<String>} scopes
|
||||
* @returns {Boolean} true if any scope matches the selector
|
||||
*/
|
||||
// Essential: Return true iff the selector matches any provided scope.
|
||||
//
|
||||
// * {String} selector
|
||||
// * {Array<String>} scopes
|
||||
// Returns {Boolean} true if any scope matches the selector.
|
||||
function selectorMatchesAnyScope (selector, scopes) {
|
||||
return !selector || scopes.some(matcherForSelector(selector))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user