11/**
22 * Case-insensitive compare two character codes
3- * @param {string } charA
4- * @param {string } charB
3+ * @param {string } referenceCode
4+ * @param {string } testCode
55 * @see https://github.com/csstree/csstree/blob/41f276e8862d8223eeaa01a3d113ab70bb13d2d9/lib/tokenizer/utils.js#L22
66 */
77function compareChar ( referenceCode , testCode ) {
@@ -15,16 +15,22 @@ function compareChar(referenceCode, testCode) {
1515
1616/**
1717 * Case-insensitive string-comparison
18- * @param {string } base
19- * @param {string } test
18+ * @example
19+ * strEquals('test', 'test') // true
20+ * strEquals('test', 'TEST') // true
21+ * strEquals('test', 'TesT') // true
22+ * strEquals('test', 'derp') // false
23+ *
24+ * @param {string } base The string to check against
25+ * @param {string } maybe The test string, possibly containing uppercased characters
2026 * @returns {boolean } true if the two strings are the same, false otherwise
2127 */
22- export function strEquals ( base , test ) {
28+ export function strEquals ( base , maybe ) {
2329 let len = base . length ;
24- if ( len !== test . length ) return false
30+ if ( len !== maybe . length ) return false
2531
2632 for ( let i = 0 ; i < len ; i ++ ) {
27- if ( compareChar ( base . charCodeAt ( i ) , test . charCodeAt ( i ) ) === false ) {
33+ if ( compareChar ( base . charCodeAt ( i ) , maybe . charCodeAt ( i ) ) === false ) {
2834 return false
2935 }
3036 }
@@ -34,20 +40,25 @@ export function strEquals(base, test) {
3440
3541/**
3642 * Case-insensitive testing whether a string ends with a given substring
43+ *
44+ * @example
45+ * endsWith('test', 'my-test') // true
46+ * endsWith('test', 'est') // false
47+ *
3748 * @param {string } base e.g. '-webkit-transform'
38- * @param {string } test e.g. 'transform'
49+ * @param {string } maybe e.g. 'transform'
3950 * @returns {boolean } true if `test` ends with `base`, false otherwise
4051 */
41- export function endsWith ( base , test ) {
42- let len = test . length
52+ export function endsWith ( base , maybe ) {
53+ let len = maybe . length
4354 let offset = len - base . length
4455
4556 if ( offset < 0 ) {
4657 return false
4758 }
4859
4960 for ( let i = len - 1 ; i >= offset ; i -- ) {
50- if ( compareChar ( base . charCodeAt ( i - offset ) , test . charCodeAt ( i ) ) === false ) {
61+ if ( compareChar ( base . charCodeAt ( i - offset ) , maybe . charCodeAt ( i ) ) === false ) {
5162 return false
5263 }
5364 }
@@ -58,15 +69,15 @@ export function endsWith(base, test) {
5869/**
5970 * Case-insensitive testing whether a string starts with a given substring
6071 * @param {string } base
61- * @param {string } test
72+ * @param {string } maybe
6273 * @returns {boolean } true if `test` starts with `base`, false otherwise
6374 */
64- export function startsWith ( base , test ) {
75+ export function startsWith ( base , maybe ) {
6576 let len = base . length
66- if ( test . length < len ) return false
77+ if ( maybe . length < len ) return false
6778
6879 for ( let i = 0 ; i < len ; i ++ ) {
69- if ( compareChar ( base . charCodeAt ( i ) , test . charCodeAt ( i ) ) === false ) {
80+ if ( compareChar ( base . charCodeAt ( i ) , maybe . charCodeAt ( i ) ) === false ) {
7081 return false
7182 }
7283 }
0 commit comments