Skip to content

Commit

Permalink
docs: Reword README a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes authored Jul 31, 2023
1 parent bfeb991 commit e4a42e1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ pip-requirements-js strictly adheres to [pip's documentation of the requirements

## API

To extract all the packages in a given file, use `parsePipRequirementsFile(fileContent: string): Requirement[]`.
To extract all the requirements from a given file, use
```typescript
parsePipRequirementsFile(fileContent: string): Requirement[]
```

To extract the package on a given line, use `parsePipRequirementsLine(lineContent: string): Requirement | null` (note that `null` will be returned if the line is empty).
To extract a requirement from a given line, use
```typescript
parsePipRequirementsLine(lineContent: string): Requirement | null
```
(note that `null` will be returned if the line is empty)

In both cases a `RequirementsSyntaxError` will be thrown if the provided content contains invalid syntax.

To make use of the resulting data, look up what `Requirement` is made up of in [`types.ts`](https://github.com/Twixes/pip-requirements-js/blob/main/src/).

## Internals

pip-requirements-js uses the robust parser generator [Ohm.js](https://github.com/ohmjs/ohm), and the core of this library is the [pep-508.ohm](https://github.com/Twixes/pip-requirements-js/blob/main/src/pep-508.ohm) grammar – a straightforward Ohm port of [PEP 508's complete dependency specification grammar](https://peps.python.org/pep-0508/#complete-grammar) (originally defined for Parsley). This ensures the greatest possible compatabibility with what pip itself does.
pip-requirements-js is built with the robust parser generator [Ohm.js](https://github.com/ohmjs/ohm) the core of this library is the [pep-508.ohm](https://github.com/Twixes/pip-requirements-js/blob/main/src/pep-508.ohm) grammar, which is an Ohm port of [PEP 508's complete dependency specification grammar](https://peps.python.org/pep-0508/#complete-grammar) (originally defined for Parsley), with some pip-specific additions (such as the `-r extra-requirements.txt` syntax). This ensures the greatest possible compatibility with what pip itself does.

0 comments on commit e4a42e1

Please sign in to comment.