Skip to content

Commit

Permalink
chore: update readme usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Aug 14, 2024
1 parent 7d41b14 commit 09d8ebf
Showing 1 changed file with 79 additions and 19 deletions.
98 changes: 79 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
# packageurl-js

### Installing:
### Installing

To install `packageurl-js` in your project, simply run:
```
```bash
npm install packageurl-js
```

This command will download the `packageurl-js` npm package for use in your application.

### Local Development:
### Local Development

Clone the `packageurl-js` repo and `cd` into the directory.

Then run:
```
```bash
npm install
```

### Testing

To run the test suite:
```
```bash
npm test
```

### Usage Examples

#### Import ES6 Module
#### Importing

```
As an ES6 module
```js
import { PackageURL } from 'packageurl-js'
```

#### Import CommonJs Module

```
As a CommonJS module
```js
const { PackageURL } = require('packageurl-js')
```

#### Parsing a string
#### Parsing

```js
const purlStr = 'pkg:maven/org.springframework.integration/[email protected]'
Expand All @@ -48,12 +51,12 @@ will both log

```
PackageURL {
type: 'maven',
name: 'spring-integration-jms',
namespace: 'org.springframework.integration',
version: '5.5.5',
qualifiers: undefined,
subpath: undefined
type: 'maven',
name: 'spring-integration-jms',
namespace: 'org.springframework.integration',
version: '5.5.5',
qualifiers: undefined,
subpath: undefined
}
```

Expand All @@ -69,7 +72,7 @@ const pkg = new PackageURL(
console.log(pkg.toString())
```

will log
=>

```
pkg:maven/org.springframework.integration/[email protected]
Expand All @@ -85,8 +88,65 @@ try {
}
```

will log
=>

```
Invalid purl: missing required "pkg" scheme component
```

#### Helper Objects

Helpers for encoding, normalizing, and validating purl components and types can
be imported directly from the module or found on the PackageURL class as static
properties.
```js
import {
PackageURL,
PurlComponent,
PurlType
} from 'packageurl-js'

PurlComponent === PackageURL.Component // => true
PurlType === PackageURL.Type // => true
```

#### PurlComponent

Contains the following properties each with their own `encode`, `normalize`,
and `validate` methods, e.g. `PurlComponent.name.validate(nameStr)`:
- type
- namespace
- name
- version
- qualifiers
- qualifierKey
- qualifierValue
- subpath

#### PurlType

Contains the following properties each with their own `normalize`, and `validate`
methods, e.g. `PurlType.npm.validate(purlObj)`:
- alpm
- apk
- bitbucket
- bitnami
- composer
- conan
- cran
- deb
- github
- gitlab
- golang
- hex
- huggingface
- luarocks
- maven
- mlflow
- npm
- oci
- pub
- pypi
- qpkg
- rpm
- swift

0 comments on commit 09d8ebf

Please sign in to comment.