1- 'use strict'
2-
3- module . exports = match
4-
5- var commas = require ( 'comma-separated-tokens' )
6- var has = require ( 'hast-util-has-property' )
7- var find = require ( 'property-information/find' )
8- var spaces = require ( 'space-separated-tokens' )
9- var zwitch = require ( 'zwitch' )
1+ import { stringify as commas } from 'comma-separated-tokens'
2+ import { hasProperty } from 'hast-util-has-property'
3+ import { find } from 'property-information'
4+ import { stringify as spaces } from 'space-separated-tokens'
5+ import { zwitch } from 'zwitch'
106
117var handle = zwitch ( 'operator' , {
128 unknown : unknownOperator ,
@@ -21,7 +17,7 @@ var handle = zwitch('operator', {
2117 }
2218} )
2319
24- function match ( query , node , schema ) {
20+ export function attribute ( query , node , schema ) {
2521 var attrs = query . attrs
2622 var index = - 1
2723
@@ -34,13 +30,13 @@ function match(query, node, schema) {
3430
3531// `[attr]`
3632function exists ( query , node , info ) {
37- return has ( node , info . property )
33+ return hasProperty ( node , info . property )
3834}
3935
4036// `[attr=value]`
4137function exact ( query , node , info ) {
4238 return (
43- has ( node , info . property ) &&
39+ hasProperty ( node , info . property ) &&
4440 normalizeValue ( node . properties [ info . property ] , info ) === query . value
4541 )
4642}
@@ -55,10 +51,11 @@ function spaceSeparatedList(query, node, info) {
5551 ( ! info . commaSeparated &&
5652 value &&
5753 typeof value === 'object' &&
58- value . indexOf ( query . value ) > - 1 ) ||
54+ value . includes ( query . value ) ) ||
5955 // For all other values (including comma-separated lists), return whether this
6056 // is an exact match.
61- ( has ( node , info . property ) && normalizeValue ( value , info ) === query . value )
57+ ( hasProperty ( node , info . property ) &&
58+ normalizeValue ( value , info ) === query . value )
6259 )
6360}
6461
@@ -67,7 +64,7 @@ function exactOrPrefix(query, node, info) {
6764 var value = normalizeValue ( node . properties [ info . property ] , info )
6865
6966 return (
70- has ( node , info . property ) &&
67+ hasProperty ( node , info . property ) &&
7168 ( value === query . value ||
7269 ( value . slice ( 0 , query . value . length ) === query . value &&
7370 value . charAt ( query . value . length ) === '-' ) )
@@ -77,7 +74,7 @@ function exactOrPrefix(query, node, info) {
7774// `[attr^=value]`
7875function begins ( query , node , info ) {
7976 return (
80- has ( node , info . property ) &&
77+ hasProperty ( node , info . property ) &&
8178 normalizeValue ( node . properties [ info . property ] , info ) . slice (
8279 0 ,
8380 query . value . length
@@ -88,7 +85,7 @@ function begins(query, node, info) {
8885// `[attr$=value]`
8986function ends ( query , node , info ) {
9087 return (
91- has ( node , info . property ) &&
88+ hasProperty ( node , info . property ) &&
9289 normalizeValue ( node . properties [ info . property ] , info ) . slice (
9390 - query . value . length
9491 ) === query . value
@@ -98,13 +95,13 @@ function ends(query, node, info) {
9895// `[attr*=value]`
9996function contains ( query , node , info ) {
10097 return (
101- has ( node , info . property ) &&
102- normalizeValue ( node . properties [ info . property ] , info ) . indexOf ( query . value ) >
103- - 1
98+ hasProperty ( node , info . property ) &&
99+ normalizeValue ( node . properties [ info . property ] , info ) . includes ( query . value )
104100 )
105101}
106102
107- /* istanbul ignore next - Shouldn’t be invoked, Parser throws an error instead. */
103+ // Shouldn’t be called, Parser throws an error instead.
104+ /* c8 ignore next 3 */
108105function unknownOperator ( query ) {
109106 throw new Error ( 'Unknown operator `' + query . operator + '`' )
110107}
@@ -120,7 +117,7 @@ function normalizeValue(value, info) {
120117 }
121118
122119 if ( typeof value === 'object' && 'length' in value ) {
123- return ( info . commaSeparated ? commas . stringify : spaces . stringify ) ( value )
120+ return ( info . commaSeparated ? commas : spaces ) ( value )
124121 }
125122
126123 return value
0 commit comments