Skip to content

Commit

Permalink
fix: search command (close #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
favoyang committed Jul 26, 2020
1 parent da0a13c commit 5093423
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/cmd-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ const searchEndpoint = async function(keyword, registry) {
return objects.map(x => {
let pkg = x.package;
let name = `${pkg.name}${pkg.displayName ? "\n" + pkg.displayName : ""}`;
const distTags = pkg["dist-tags"];
const version = distTags && distTags["latest"] ? distTags["latest"] : "";
let author = pkg.author ? pkg.author.name : "";
let date = pkg.date ? pkg.date.split("T")[0] : "";
let date =
pkg.time && pkg.time.modified ? pkg.time.modified.split("T")[0] : "";
let keywords = (pkg.keywords || []).join(", ");
let item = [name, pkg.version, author, date, keywords];
let item = [name, version, author, date, keywords];
log.debug(item);
return item;
});
} catch (err) {
Expand Down
9 changes: 7 additions & 2 deletions test/test-cmd-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ describe("cmd-search.js", function() {
package: {
name: "com.example.package-a",
scope: "unscoped",
version: "1.0.0",
"dist-tags": { latest: "1.0.0" },
versions: {
"1.0.0": "latest"
},
description: "A demo package",
date: "2019-10-02T04:02:38.335Z",
time: {
modified: "2019-10-02T04:02:38.335Z"
},
links: {},
author: { name: "yo", url: "https://github.com/yo" },
publisher: { username: "yo", email: "yo@example.com" },
Expand Down

0 comments on commit 5093423

Please sign in to comment.