|
1 | 1 | # packageurl-js |
2 | 2 |
|
3 | | -### Installing: |
| 3 | +### Installing |
| 4 | + |
4 | 5 | To install `packageurl-js` in your project, simply run: |
5 | | -``` |
| 6 | +```bash |
6 | 7 | npm install packageurl-js |
7 | 8 | ``` |
8 | 9 |
|
9 | 10 | This command will download the `packageurl-js` npm package for use in your application. |
10 | 11 |
|
11 | | -### Local Development: |
12 | | -Clone the `packageurl-js` repo and `cd` into the directory. |
| 12 | +### Local Development |
13 | 13 |
|
14 | | -Then run: |
15 | | -``` |
| 14 | +Clone the `packageurl-js` repo and `cd` into the directory. |
| 15 | + |
| 16 | +Then run: |
| 17 | +```bash |
16 | 18 | npm install |
17 | 19 | ``` |
18 | 20 |
|
19 | 21 | ### Testing |
20 | | -To run the test suite: |
21 | | -``` |
| 22 | + |
| 23 | +To run the test suite: |
| 24 | +```bash |
22 | 25 | npm test |
23 | 26 | ``` |
24 | 27 |
|
25 | 28 | ### Usage Examples |
26 | 29 |
|
27 | | -#### Import ES6 Module |
| 30 | +#### Importing |
28 | 31 |
|
| 32 | +As an ES6 module |
| 33 | +```js |
| 34 | +import { PackageURL } from 'packageurl-js' |
29 | 35 | ``` |
30 | | -import { PackageURL } from 'packageurl-js'; |
31 | | -``` |
32 | | - |
33 | | -#### Import CommonJs Module |
34 | 36 |
|
35 | | -``` |
36 | | -const { PackageURL } = require('packageurl-js'); |
| 37 | +As a CommonJS module |
| 38 | +```js |
| 39 | +const { PackageURL } = require('packageurl-js') |
37 | 40 | ``` |
38 | 41 |
|
39 | | -#### Parsing from a string |
| 42 | +#### Parsing |
40 | 43 |
|
41 | | -``` |
42 | | -const pkg = PackageURL.fromString('pkg:maven/org.springframework.integration/[email protected]'); |
43 | | -console.log(pkg); |
| 44 | +```js |
| 45 | +const purlStr = 'pkg:maven/org.springframework.integration/[email protected]' |
| 46 | +console.log(PackageURL.fromString(purlStr)) |
| 47 | +console.log(new PackageURL(...PackageURL.parseString(purlStr))) |
44 | 48 | ``` |
45 | 49 |
|
46 | | -=> |
| 50 | +will both log |
47 | 51 |
|
48 | 52 | ``` |
49 | 53 | PackageURL { |
50 | | - type: 'maven', |
51 | | - name: 'spring-integration-jms', |
52 | | - namespace: 'org.springframework.integration', |
53 | | - version: '5.5.5', |
54 | | - qualifiers: null, |
55 | | - subpath: null |
| 54 | + type: 'maven', |
| 55 | + name: 'spring-integration-jms', |
| 56 | + namespace: 'org.springframework.integration', |
| 57 | + version: '5.5.5', |
| 58 | + qualifiers: undefined, |
| 59 | + subpath: undefined |
56 | 60 | } |
57 | 61 | ``` |
58 | 62 |
|
59 | 63 | #### Constructing |
60 | 64 |
|
61 | | -``` |
| 65 | +```js |
62 | 66 | const pkg = new PackageURL( |
63 | 67 | 'maven', |
64 | 68 | 'org.springframework.integration', |
65 | 69 | 'spring-integration-jms', |
66 | | - '5.5.5', |
67 | | - undefined, |
68 | | - undefined); |
69 | | -
|
70 | | -console.log(pkg.toString()); |
| 70 | + '5.5.5' |
| 71 | +) |
| 72 | +console.log(pkg.toString()) |
71 | 73 | ``` |
72 | 74 |
|
73 | 75 | => |
|
78 | 80 |
|
79 | 81 | #### Error Handling |
80 | 82 |
|
81 | | -``` |
| 83 | +```js |
82 | 84 | try { |
83 | | - PackageURL.fromString('not-a-purl'); |
84 | | -} catch(ex) { |
85 | | - console.error(ex.message); |
| 85 | + PackageURL.fromString('not-a-purl') |
| 86 | +} catch (e) { |
| 87 | + console.error(e.message) |
86 | 88 | } |
87 | 89 | ``` |
88 | 90 |
|
89 | 91 | => |
90 | 92 |
|
91 | 93 | ``` |
92 | | -purl is missing the required "pkg" scheme component. |
93 | | -``` |
| 94 | +Invalid purl: missing required "pkg" scheme component |
| 95 | +``` |
| 96 | + |
| 97 | +#### Helper Objects |
| 98 | + |
| 99 | +Helpers for encoding, normalizing, and validating purl components and types can |
| 100 | +be imported directly from the module or found on the PackageURL class as static |
| 101 | +properties. |
| 102 | +```js |
| 103 | +import { |
| 104 | + PackageURL, |
| 105 | + PurlComponent, |
| 106 | + PurlType |
| 107 | +} from 'packageurl-js' |
| 108 | + |
| 109 | +PurlComponent === PackageURL.Component // => true |
| 110 | +PurlType === PackageURL.Type // => true |
| 111 | +``` |
| 112 | + |
| 113 | +#### PurlComponent |
| 114 | + |
| 115 | +Contains the following properties each with their own `encode`, `normalize`, |
| 116 | +and `validate` methods, e.g. `PurlComponent.name.validate(nameStr)`: |
| 117 | + - type |
| 118 | + - namespace |
| 119 | + - name |
| 120 | + - version |
| 121 | + - qualifiers |
| 122 | + - qualifierKey |
| 123 | + - qualifierValue |
| 124 | + - subpath |
| 125 | + |
| 126 | +#### PurlType |
| 127 | + |
| 128 | +Contains the following properties each with their own `normalize`, and `validate` |
| 129 | +methods, e.g. `PurlType.npm.validate(purlObj)`: |
| 130 | + - alpm |
| 131 | + - apk |
| 132 | + - bitbucket |
| 133 | + - bitnami |
| 134 | + - composer |
| 135 | + - conan |
| 136 | + - cran |
| 137 | + - deb |
| 138 | + - github |
| 139 | + - gitlab |
| 140 | + - golang |
| 141 | + - hex |
| 142 | + - huggingface |
| 143 | + - luarocks |
| 144 | + - maven |
| 145 | + - mlflow |
| 146 | + - npm |
| 147 | + - oci |
| 148 | + - pub |
| 149 | + - pypi |
| 150 | + - qpkg |
| 151 | + - rpm |
| 152 | + - swift |
0 commit comments