Socket
Socket
Sign inDemoInstall

parserlib

Package Overview
Dependencies
0
Maintainers
5
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

4

package.json
{
"name": "parserlib",
"version": "1.0.0",
"version": "1.1.0",
"author": "Nicholas C. Zakas",

@@ -43,3 +43,3 @@ "contributors": [

"moment": "^2.11.2",
"shelljs": "^0.6.0",
"shelljs": "^0.7.5",
"ytestrunner": "^0.3.3",

@@ -46,0 +46,0 @@ "yuitest": "^0.7.9"

@@ -49,3 +49,4 @@ # CSS Parser

To use the CSS parser on an HTML page, you can either include the entire library on your page:
To use the CSS parser on an HTML page, you can either include the entire
library on your page:

@@ -75,8 +76,13 @@ ```html

The constructor accepts an options object that specifies additional features the parser should use. The available options are:
The constructor accepts an options object that specifies additional features
the parser should use. The available options are:
* `starHack` - set to true to treat properties with a leading asterisk as if the asterisk wasn't there. Default is false.
* `underscoreHack` - set to true to treat properties with a leading underscore as if the underscore wasn't there. Default is false.
* `ieFilters` - set to true to accept IE < 8 style `filter` properties. Default is false.
* `strict` - set to true to disable error recovery and stop on the first syntax error. Default is false.
* `starHack` - set to true to treat properties with a leading asterisk as if
the asterisk wasn't there. Default is `false`.
* `underscoreHack` - set to true to treat properties with a leading underscore
as if the underscore wasn't there. Default is `false`.
* `ieFilters` - set to true to accept IE < 8 style `filter` properties.
Default is `false`.
* `strict` - set to true to disable error recovery and stop on the first
syntax error. Default is `false`.

@@ -95,7 +101,10 @@ Here's an example with some options set:

The `parse()` method throws an error if a non-recoverable syntax error occurs, otherwise it finishes silently.
This method does not return a value nor does it build up an abstract syntax tree (AST) for you,
it simply parses the CSS text and fires events at important moments along the parse.
The `parse()` method throws an error if a non-recoverable syntax error occurs,
otherwise it finishes silently.
This method does not return a value nor does it build up an abstract syntax
tree (AST) for you, it simply parses the CSS text and fires events at important
moments along the parse.
Note: The `parseStyleSheet()` method is provided for compatibility with SAC-based APIs but does the exact same thing as `parse()`.
Note: The `parseStyleSheet()` method is provided for compatibility with
SAC-based APIs but does the exact same thing as `parse()`.

@@ -109,5 +118,6 @@ ## Understanding syntax units

The `parserlib.css.MediaFeature` type represents a specific media feature in a media query,
such as `(orientation: portrait)` or `(color)`. Essentially, this type of object represents
anything enclosed in parentheses in a media query. Object of this type have the following properties:
The `parserlib.css.MediaFeature` type represents a specific media feature in a
media query, such as `(orientation: portrait)` or `(color)`. Essentially, this
type of object represents anything enclosed in parentheses in a media query.
Object of this type have the following properties:

@@ -153,3 +163,4 @@ * `name` - the name of the media feature such as "orientation"

The `parserlib.css.PropertyValuePart` type represents an individual part of a property value. Each instance has the following properties:
The `parserlib.css.PropertyValuePart` type represents an individual part of a
property value. Each instance has the following properties:

@@ -170,5 +181,6 @@ * `type` - the type of value part ("unknown", "dimension", "percentage", "integer", "number", "color", "uri", "string", "identifier" or "operator")

The `parserlib.css.Selector` type represents a single selector. Each instance has a `parts` property,
which is an array of `parserlib.css.SelectorPart` objects, which represent atomic parts of the selector,
and `parserlib.css.Combinator` objects, which represent combinators in the selector.
The `parserlib.css.Selector` type represents a single selector. Each instance
has a `parts` property, which is an array of `parserlib.css.SelectorPart` objects,
which represent atomic parts of the selector, and `parserlib.css.Combinator`
objects, which represent combinators in the selector.
Consider the following selector:

@@ -180,5 +192,6 @@

This selector has three parts: `li.selected`, `>`, and `a:hover`. The first part is a `SelectorPart`,
the second is a `Combinator`, and the third is a `SelectorPart`. Each `SelectorPart` is made up
of an optional element name followed by an ID, class, attribute condition, pseudo class, and/or pseudo element.
This selector has three parts: `li.selected`, `>`, and `a:hover`. The first
part is a `SelectorPart`, the second is a `Combinator`, and the third is a
`SelectorPart`. Each `SelectorPart` is made up of an optional element name
followed by an ID, class, attribute condition, pseudo class, and/or pseudo element.

@@ -196,3 +209,2 @@ Each instance of `parserlib.css.SelectorPart` has an `elementName` property, which represents

## Using events

@@ -225,7 +237,7 @@

parser.addListener("startstylesheet", function() {
console.log("Starting to parse style sheet");
console.log("Starting to parse stylesheet");
});
parser.addListener("endstylesheet", function() {
console.log("Finished parsing style sheet");
console.log("Finished parsing stylesheet");
});

@@ -236,6 +248,6 @@ ```

The `charset` event fires when the `@charset` directive is found in a style sheet.
Since `@charset` is required to appear first in a style sheet, any other occurances
The `charset` event fires when the `@charset` directive is found in a stylesheet.
Since `@charset` is required to appear first in a stylesheet, any other occurances
cause a syntax error. The `charset` event provides an `event` object with a property
called `charset`, which contains the name of the character set for the style sheet. Example:
called `charset`, which contains the name of the character set for the stylesheet. Example:

@@ -250,3 +262,3 @@ ```js

The `namespace` event fires when the `@namespace` directive is found in a style sheet.
The `namespace` event fires when the `@namespace` directive is found in a stylesheet.
The `namespace` event provides an `event` object with two properties: `prefix`,

@@ -263,3 +275,3 @@ which is the namespace prefix, and `uri`, which is the namespace URI. Example:

The `import` event fires when the `@import` directive is found in a style sheet.
The `import` event fires when the `@import` directive is found in a stylesheet.
The `import` event provides an `event` object with two properties: `uri`,

@@ -294,4 +306,4 @@ which is the URI to import, and `media`, which is an array of media queries

The `startpage` event fires when `@page` is encountered and the `endpage` event fires
just after the closing right brace (`}`) is encountered after `@page`.
The `startpage` event fires when `@page` is encountered and the `endpage` event
fires just after the closing right brace (`}`) is encountered after `@page`.
The `event` object has two properties: `id`, which is the page ID, and `pseudo`,

@@ -329,5 +341,5 @@ which is the page pseudo class. Example:

The `startmedia` event fires when `@media` is encountered and the `endmedia` event fires
just after the closing right brace (`}`) is encountered after `@media`.
The `event` object has one property, `media`, which is an array of
The `startmedia` event fires when `@media` is encountered and the `endmedia`
event fires just after the closing right brace (`}`) is encountered after
`@media`. The `event` object has one property, `media`, which is an array of
`parserlib.css.MediaQuery` objects. Example:

@@ -435,3 +447,4 @@

* **Properties** - a syntactically incorrect property definition will be skipped over completely. For instance, the second property below is dropped:
* **Properties** - a syntactically incorrect property definition will be
skipped over completely. For instance, the second property below is dropped:

@@ -441,3 +454,3 @@ ```css

color: red;
font:: Helvetica; /* dropped! */
font:: Helvetica; /* dropped! */
text-decoration: underline;

@@ -447,3 +460,4 @@ }

* **Selectors** - if there's a syntax error in *any* selector, the entire rule is skipped over. For instance, the following rule is completely skipped:
* **Selectors** - if there's a syntax error in *any* selector, the entire rule
is skipped over. For instance, the following rule is completely skipped:

@@ -458,9 +472,12 @@ ```css

* **@ Rules** - there are certain @ rules that are only valid in certain contexts. The parser will skip over `@charset`, `@namespace`, and `@import` if they're found anywhere other than the beginning of the input.
* **@ Rules** - there are certain @ rules that are only valid in certain
contexts. The parser will skip over `@charset`, `@namespace`, and `@import`
if they're found anywhere other than the beginning of the input.
* **Unknown @ Rules** - any @ rules that isn't recognized is automatically skipped, meaning the entire block after it is not parsed.
* **Unknown @ Rules** - any @ rules that isn't recognized is automatically
skipped, meaning the entire block after it is not parsed.
## Running Tests
You can run the tests via `npm test` from the repository's root. You
You can run the tests via `npm test` from the repository's root. You
may need to run `npm install` first to install the necessary dependencies.

@@ -12,2 +12,3 @@ "use strict";

"align-self" : "auto | flex-start | flex-end | center | baseline | stretch",
"all" : "initial | inherit | unset",
"-webkit-align-items" : "flex-start | flex-end | center | baseline | stretch",

@@ -58,3 +59,8 @@ "-webkit-align-content" : "flex-start | flex-end | center | space-between | space-around | stretch",

"appearance" : "icon | window | desktop | workspace | document | tooltip | dialog | button | push-button | hyperlink | radio | radio-button | checkbox | menu-item | tab | menu | menubar | pull-down-menu | pop-up-menu | list-menu | radio-group | checkbox-group | outline-tree | range | field | combo-box | signature | password | normal | none",
"appearance" : "none | auto",
"-moz-appearance" : "none | button | button-arrow-down | button-arrow-next | button-arrow-previous | button-arrow-up | button-bevel | button-focus | caret | checkbox | checkbox-container | checkbox-label | checkmenuitem | dualbutton | groupbox | listbox | listitem | menuarrow | menubar | menucheckbox | menuimage | menuitem | menuitemtext | menulist | menulist-button | menulist-text | menulist-textfield | menupopup | menuradio | menuseparator | meterbar | meterchunk | progressbar | progressbar-vertical | progresschunk | progresschunk-vertical | radio | radio-container | radio-label | radiomenuitem | range | range-thumb | resizer | resizerpanel | scale-horizontal | scalethumbend | scalethumb-horizontal | scalethumbstart | scalethumbtick | scalethumb-vertical | scale-vertical | scrollbarbutton-down | scrollbarbutton-left | scrollbarbutton-right | scrollbarbutton-up | scrollbarthumb-horizontal | scrollbarthumb-vertical | scrollbartrack-horizontal | scrollbartrack-vertical | searchfield | separator | sheet | spinner | spinner-downbutton | spinner-textfield | spinner-upbutton | splitter | statusbar | statusbarpanel | tab | tabpanel | tabpanels | tab-scroll-arrow-back | tab-scroll-arrow-forward | textfield | textfield-multiline | toolbar | toolbarbutton | toolbarbutton-dropdown | toolbargripper | toolbox | tooltip | treeheader | treeheadercell | treeheadersortarrow | treeitem | treeline | treetwisty | treetwistyopen | treeview | -moz-mac-unified-toolbar | -moz-win-borderless-glass | -moz-win-browsertabbar-toolbox | -moz-win-communicationstext | -moz-win-communications-toolbox | -moz-win-exclude-glass | -moz-win-glass | -moz-win-mediatext | -moz-win-media-toolbox | -moz-window-button-box | -moz-window-button-box-maximized | -moz-window-button-close | -moz-window-button-maximize | -moz-window-button-minimize | -moz-window-button-restore | -moz-window-frame-bottom | -moz-window-frame-left | -moz-window-frame-right | -moz-window-titlebar | -moz-window-titlebar-maximized",
"-ms-appearance" : "none | icon | window | desktop | workspace | document | tooltip | dialog | button | push-button | hyperlink | radio | radio-button | checkbox | menu-item | tab | menu | menubar | pull-down-menu | pop-up-menu | list-menu | radio-group | checkbox-group | outline-tree | range | field | combo-box | signature | password | normal",
"-webkit-appearance" : "none | button | button-bevel | caps-lock-indicator | caret | checkbox | default-button | listbox | listitem | media-fullscreen-button | media-mute-button | media-play-button | media-seek-back-button | media-seek-forward-button | media-slider | media-sliderthumb | menulist | menulist-button | menulist-text | menulist-textfield | push-button | radio | searchfield | searchfield-cancel-button | searchfield-decoration | searchfield-results-button | searchfield-results-decoration | slider-horizontal | slider-vertical | sliderthumb-horizontal | sliderthumb-vertical | square-button | textarea | textfield | scrollbarbutton-down | scrollbarbutton-left | scrollbarbutton-right | scrollbarbutton-up | scrollbargripper-horizontal | scrollbargripper-vertical | scrollbarthumb-horizontal | scrollbarthumb-vertical | scrollbartrack-horizontal | scrollbartrack-vertical",
"-o-appearance" : "none | window | desktop | workspace | document | tooltip | dialog | button | push-button | hyperlink | radio | radio-button | checkbox | menu-item | tab | menu | menubar | pull-down-menu | pop-up-menu | list-menu | radio-group | checkbox-group | outline-tree | range | field | combo-box | signature | password | normal",
"azimuth" : "<azimuth>",

@@ -430,3 +436,6 @@

"text-anchor" : "start | middle | end",
"text-decoration" : "<text-decoration>",
"text-decoration" : "<text-decoration-line> || <text-decoration-style> || <text-decoration-color>",
"text-decoration-color" : "<text-decoration-color>",
"text-decoration-line" : "<text-decoration-line>",
"text-decoration-style" : "<text-decoration-style>",
"text-emphasis" : 1,

@@ -433,0 +442,0 @@ "text-height" : 1,

@@ -71,2 +71,3 @@ "use strict";

case "grad":
case "turn":
this.type = "angle";

@@ -73,0 +74,0 @@ break;

@@ -664,3 +664,3 @@ "use strict";

tt = Tokens.LENGTH;
} else if (/^deg|^rad$|^grad$/i.test(ident)) {
} else if (/^deg|^rad$|^grad$|^turn$/i.test(ident)) {
tt = Tokens.ANGLE;

@@ -1049,2 +1049,1 @@ } else if (/^ms$|^s$/i.test(ident)) {

});

@@ -436,5 +436,11 @@ "use strict";

"<text-decoration>":
"<text-decoration-color>":
"<color>",
"<text-decoration-line>":
"none | [ underline || overline || line-through || blink ]",
"<text-decoration-style>":
"solid | double | dotted | dashed | wavy",
"<will-change>":

@@ -441,0 +447,0 @@ "auto | <animateable-feature>#",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc