Skip to content

Commit

Permalink
feat(docs): Add JSDocs to exported functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Oct 9, 2020
1 parent e4b589d commit 6b60fa9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ CSSwhat.parse("foo[bar]:baz")

## API

**`CSSwhat.parse(str, options)` - Parses `str`, optionally with the passed `options`.**
**`CSSwhat.parse(selector, options)` - Parses `selector`, optionally with the passed `options`.**

The function returns a two-dimensional array. The first array represents selectors separated by commas (eg. `sub1, sub2`), the second contains the relevant tokens for that selector. Possible token types are:

| name | attributes | example | output |
| name | properties | example | output |
| ---------------- | --------------------------------------- | ------------- | ---------------------------------------------------------------------------------------- |
| `tag` | `name` | `div` | `{ type: 'tag', name: 'div' }` |
| `universal` | - | `*` | `{ type: 'universal' }` |
Expand Down
30 changes: 25 additions & 5 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
"use strict";

export default parse;

export interface Options {
/**
* When false, tag names will not be lowercased.
* @default true
*/
lowerCaseAttributeNames?: boolean;
/**
* When false, attribute names will not be lowercased.
* @default true
*/
lowerCaseTags?: boolean;
/**
* When `true`, `xmlMode` implies both `lowerCaseTags` and `lowerCaseAttributeNames` are set to `false`.
* @default false
*/
xmlMode?: boolean;
}

Expand Down Expand Up @@ -131,7 +139,19 @@ function isWhitespace(c: string) {
return c === " " || c === "\n" || c === "\t" || c === "\f" || c === "\r";
}

function parse(selector: string, options?: Options): Selector[][] {
/**
* Parses `selector`, optionally with the passed `options`.
*
* @param selector Selector to parse.
* @param options Options for parsing.
* @returns Returns a two-dimensional array.
* The first dimension represents selectors separated by commas (eg. `sub1, sub2`),
* the second contains the relevant tokens for that selector.
*/
export default function parse(
selector: string,
options?: Options
): Selector[][] {
const subselects: Selector[][] = [];

selector = parseSelector(subselects, `${selector}`, options);
Expand Down
9 changes: 7 additions & 2 deletions src/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ const charsToEscape = new Set([
"\\",
]);

export default function stringify(token: Selector[][]): string {
return token.map(stringifySubselector).join(", ");
/**
* Turns `selector` back into a string.
*
* @param selector Selector to stringify.
*/
export default function stringify(selector: Selector[][]): string {
return selector.map(stringifySubselector).join(", ");
}

function stringifySubselector(token: Selector[]): string {
Expand Down

0 comments on commit 6b60fa9

Please sign in to comment.