Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
major: update & push to github
Browse files Browse the repository at this point in the history
Signed-off-by: Charlike Mike Reagent <mameto2011@gmail.com>
  • Loading branch information
Charlike Mike Reagent committed Nov 6, 2018
1 parent ef3c980 commit e755f9e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .nycrc.json
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
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"node": "^8.11.0 || >=10.13.0"
},
"dependencies": {
"esm": "^3.0.84"
"axios": "^0.18.0",
"esm": "^3.0.84",
"parse-package-name": "^0.1.0"
},
"devDependencies": {
"@tunnckocore/config": "^0.5.1",
Expand Down
15 changes: 14 additions & 1 deletion src/index.js
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);
}
15 changes: 12 additions & 3 deletions test/index.js
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');
});
1 change: 1 addition & 0 deletions test/snapshots/index.snapshot.json
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"}}
35 changes: 31 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@
p-map-series "1.0.0"
split-cmd "^1.0.0"

"@tunnckocore/scripts@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@tunnckocore/scripts/-/scripts-1.0.1.tgz#7cc92e3fc5d5fcbc82992e222e1ef1b685c19ae2"
integrity sha512-yjKYbfqla6Qx3gSTP9ITjlkkJ5/JF+SnMKhjdo5I3GXAAar63IYVnu3elMQpkMaSXmiNLiiIp8HrRB0U0tivNA==
"@tunnckocore/scripts@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@tunnckocore/scripts/-/scripts-1.1.0.tgz#52fa83dcbb6ebff1880569186421c2851b976ed9"
integrity sha512-1b2YmmzwmC86ad5mfNWJFZQnuSeEeKiw6cq4joCx5F4sAKuIVUsvafS9ehIWVtxln1BkUArEyAC6iWYAgG4lSg==
dependencies:
"@tunnckocore/execa" "^2.0.2"
esm "^3.0.84"
Expand Down Expand Up @@ -361,6 +361,14 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==

axios@^0.18.0:
version "0.18.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.0.tgz#32d53e4851efdc0a11993b6cd000789d70c05102"
integrity sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=
dependencies:
follow-redirects "^1.3.0"
is-buffer "^1.1.5"

axobject-query@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.0.2.tgz#ea187abe5b9002b377f925d8bf7d1c561adf38f9"
Expand Down Expand Up @@ -725,6 +733,13 @@ debug-log@^1.0.1:
resolved "https://registry.yarnpkg.com/debug-log/-/debug-log-1.0.1.tgz#2307632d4c04382b8df8a32f70b895046d52745f"
integrity sha1-IwdjLUwEOCuN+KMvcLiVBG1SdF8=

debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"

debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down Expand Up @@ -1418,6 +1433,13 @@ flat-cache@^1.2.1:
graceful-fs "^4.1.2"
write "^0.2.1"

follow-redirects@^1.3.0:
version "1.5.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.9.tgz#c9ed9d748b814a39535716e531b9196a845d89c6"
integrity sha512-Bh65EZI/RU8nx0wbYF9shkFZlqLP+6WT/5FnA3cE/djNSuKNHJEinGGZgu/cQEkeeb2GdFOgenAmn8qaqYke2w==
dependencies:
debug "=3.1.0"

for-in@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
Expand Down Expand Up @@ -2873,6 +2895,11 @@ parse-ms@^1.0.0:
resolved "https://registry.yarnpkg.com/parse-ms/-/parse-ms-1.0.1.tgz#56346d4749d78f23430ca0c713850aef91aa361d"
integrity sha1-VjRtR0nXjyNDDKDHE4UK75GqNh0=

parse-package-name@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/parse-package-name/-/parse-package-name-0.1.0.tgz#3f44dd838feb4c2be4bf318bae4477d7706bade4"
integrity sha1-P0Tdg4/rTCvkvzGLrkR313BrreQ=

pascalcase@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
Expand Down

0 comments on commit e755f9e

Please sign in to comment.