UNPKG

simmerjs

Version:

A pure Javascript reverse CSS selector engine which calculates a DOM element's unique CSS selector on the current page.

41 lines (39 loc) 1.32 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.tagName = tagName; exports.attr = attr; exports.className = className; /** * Validate the syntax of a tagName to make sure that it has a valid syntax for the query engine. * Many libraries use invalid property and tag names, such as Facebook that use FB: prefixed tags. * These make the query engines fail and must be filtered out. * @param {string} tagName. The element's tag name */ function tagName(tagName) { if (typeof tagName === 'string' && tagName.match(/^[a-zA-Z0-9]+$/gi) !== null) { return tagName; } return false; } /** * Validate the syntax of an attribute to make sure that it has a valid syntax for the query engine. * @param {string} attribute. The element's attribute's value */ function attr(attribute) { if (typeof attribute === 'string' && attribute.match(/^[0-9a-zA-Z][a-zA-Z_\-:0-9.]*$/gi) !== null) { return attribute; } return false; } /** * Validate the syntax of an attribute to make sure that it has a valid syntax for the query engine. * @param {string} attribute. The element's attribute's value */ function className(className) { if (typeof className === 'string' && className.match(/^\.?[a-zA-Z_\-:0-9]*$/gi) !== null) { return className; } return false; }