This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charlike Mike Reagent <mameto2011@gmail.com>
- Loading branch information
Charlike Mike Reagent
committed
Nov 6, 2018
1 parent
ef3c980
commit e755f9e
Showing
6 changed files
with
66 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
{ | ||
"extends": "./node_modules/@tunnckocore/config/nyc.json" | ||
"extends": "./node_modules/@tunnckocore/config/nyc.json", | ||
"statements": 100, | ||
"branches": 100, | ||
"functions": 100, | ||
"lines": 100 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
export default () => {}; | ||
import parse from 'parse-package-name'; | ||
import axios from 'axios'; | ||
|
||
// packageName: String, endpoint: (name: String, tag: String = 'latest'): String => {} | ||
export default async function packageJson(packageName, endpoint) { | ||
const { name, version } = parse(packageName); | ||
const tag = version === '' ? 'latest' : version; | ||
const url = | ||
typeof endpoint === 'function' | ||
? endpoint(name, tag) | ||
: `https://unpkg.com/${name}@${tag}/package.json`; | ||
|
||
return axios.get(url).then((res) => res.data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import test from 'asia'; | ||
import mod from '../src'; | ||
import packageJson from '../src'; | ||
|
||
test('todo', (t) => { | ||
t.strictEqual(typeof mod, 'function'); | ||
test('should get package metadata from UNPKG by default', async (t) => { | ||
const pkg = await packageJson('@tunnckocore/package-json'); | ||
|
||
t.strictEqual(pkg.name, '@tunnckocore/package-json'); | ||
}); | ||
|
||
test('get package metadata from npm registry', async (t) => { | ||
const endpoint = (name, tag) => `https://registry.npmjs.org/${name}/${tag}`; | ||
const pkg = await packageJson('package-json@4.0.0', endpoint); | ||
|
||
t.strictEqual(pkg.name, 'package-json'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"should get package metadata from UNPKG by default":{"skip":false,"todo":false,"run":false,"isPending":false,"isRejected":false,"isFulfilled":true,"id":1,"str":"async (t) => {\n const pkg = await packageJson('@tunnckocore/package-json');\n\n t.strictEqual(pkg.name, '@tunnckocore/package-json');\n}","title":"should get package metadata from UNPKG by default"},"get package metadata from npm registry":{"skip":false,"todo":false,"run":false,"isPending":false,"isRejected":false,"isFulfilled":true,"id":2,"str":"async (t) => {\n const endpoint = (name, tag) => `https://registry.npmjs.org/${name}/${tag}`;\n const pkg = await packageJson('package-json@4.0.0', endpoint);\n\n t.strictEqual(pkg.name, 'package-json');\n}","title":"get package metadata from npm registry"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters