Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some typos #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ A node can have one of these types (according to [the 2012 CSS3 standard](https:

* `media-query-list`: that is the root level node of the parsing result. A [container](#containers); its children can have types of `url` and `media-query`.
* `url`: if a source is taken from a CSS `@import` rule, it will have a `url(...)` function call. The value of such node will be `url(http://uri-address)`, it is to be parsed separately.
* `media-query`: such nodes correspond to each media query in a comma separated list. In the exapmle above there are two. Nodes of this type are [containers](#containers).
* `media-query`: such nodes correspond to each media query in a comma separated list. In the example above there are two. Nodes of this type are [containers](#containers).
* `media-type`: `screen`, `tv` and other media types.
* `keyword`: `only`, `not` or `and` keyword.
* `media-feature-expression`: an expression in parentheses that checks for a condition of a particular media feature. The value would be like this: `(max-width: 1000px)`. Such nodes are [containers](#containers). They always have a `media-feature` child node, but might not have a `value` child node (like in `screen and (color)`).
Expand All @@ -145,7 +145,7 @@ postcss-media-query-parser allows for cases of some **non-standard syntaxes** an

`#{$media-type}` will be the node of type `media-type`, alghough `$media-type`'s value can be `only screen`. And inside `media-feature-expression` there will only be a `media-feature` type node with the value of `#{"max-width" + ": 10px"}` (this example doesn't make much sense, it's for demo purpose).

But the result of parsing **malformed media queries** (such as with incorrect amount of closing parens, curly braces, etc.) can be unexpected. For exapmle, parsing:
But the result of parsing **malformed media queries** (such as with incorrect amount of closing parens, curly braces, etc.) can be unexpected. For example, parsing:

```scss
@media ((min-width: -100px)
Expand All @@ -162,7 +162,7 @@ Containers are [nodes](#nodes) that have other nodes as children. Container node

In both cases `callback` takes these parameters:

- `node` - the current node (one of the container's descendats, that the callback has been called against).
- `node` - the current node (one of the container's descendants, that the callback has been called against).
- `i` - 0-based index of the `node` in an array of its parent's children.
- `nodes` - array of child nodes of `node`'s parent.

Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* Some nodes (media queries, media feature expressions) contain other nodes.
* They additionally have:
* {array} node.nodes -- an array of nodes of the type described here
* {funciton} node.each -- traverses direct children of the node, calling
* {function} node.each -- traverses direct children of the node, calling
* a callback for each one
* {funciton} node.walk -- traverses ALL descendants of the node, calling
* {function} node.walk -- traverses ALL descendants of the node, calling
* a callback for each one
*/

Expand Down
10 changes: 5 additions & 5 deletions src/nodes/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Container.constructor = Node;
*
* @param {RegExp|string} filter - Optional. Only nodes with node.type that
* satisfies the filter will be traversed over
* @param {function} cb - callback to call on each node. Takes theese params:
* @param {function} cb - callback to call on each node. Takes these params:
* node - the node being processed, i - it's index, nodes - the array
* of all nodes
* If false is returned, the iteration breaks
Expand All @@ -48,7 +48,7 @@ Container.prototype.walk = function walk(filter, cb) {
const callback = hasFilter ? cb : filter;
const filterReg = typeof filter === 'string' ? new RegExp(filter) : filter;

for (let i = 0; i < this.nodes.length; i ++) {
for (let i = 0; i < this.nodes.length; i++) {
const node = this.nodes[i];
const filtered = hasFilter ? filterReg.test(node.type) : true;
if (filtered && callback && callback(node, i, this.nodes) === false) {
Expand All @@ -62,15 +62,15 @@ Container.prototype.walk = function walk(filter, cb) {
/**
* Iterate over immediate children of the node
*
* @param {function} cb - callback to call on each node. Takes theese params:
* @param {function} cb - callback to call on each node. Takes these params:
* node - the node being processed, i - it's index, nodes - the array
* of all nodes
* If false is returned, the iteration breaks
*
* @return (boolean) false, if the iteration was broken
*/
Container.prototype.each = function each(cb = () => {}) {
for (let i = 0; i < this.nodes.length; i ++) {
Container.prototype.each = function each(cb = () => { }) {
for (let i = 0; i < this.nodes.length; i++) {
const node = this.nodes[i];
if (cb(node, i, this.nodes) === false) { return false; }
}
Expand Down