-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update search tests and lintings #40
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -7,5 +7,5 @@ module.exports = { | |
conf, | ||
download, | ||
paths, | ||
search | ||
search, | ||
}; |
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,29 +1,42 @@ | ||
const http = require('http'); | ||
|
||
const getSearchUrl = pkg => `http://npmsearch.com/query\?q\=${pkg}%20AND%20\(keywords:dext-theme%20OR%20keywords:dext-plugin\)\&fields\=name`; | ||
/** | ||
* Retrieves the API url | ||
* | ||
* @param {String} q - The keyword to search | ||
* @return {String} | ||
*/ | ||
const getSearchUrl = q => `https://npmsearch.com/query?q=${q}%20AND%20(keywords:dext-theme%20OR%20keywords:dext-plugin)&fields=name,description`; | ||
|
||
/** | ||
* Searches for package marked with the keywords 'dext-plugin' or 'dext-theme' | ||
* Searches for packages marked with the keywords 'dext-plugin' or 'dext-theme' | ||
* | ||
* { name, desc } | ||
* | ||
* @param {String} pkg - The name of the npm package | ||
* @return {Promise} - The search results | ||
* @param {String} q - A keyword to search for (queried by package name) | ||
* @return {Promise} - Resolves an array of the package names and descriptions | ||
*/ | ||
const searchPackages = (pkg) => new Promise((resolve) => { | ||
const searchPackages = q => new Promise((resolve) => { | ||
let body = ''; | ||
const endpoint = getSearchUrl(q); | ||
// Retrieve the search results | ||
return http.get(getSearchUrl(pkg), (res) => { | ||
return http.get(endpoint, (res) => { | ||
res.on('data', (chunk) => { | ||
body += chunk; | ||
}); | ||
res.on('end', () => { | ||
const results = JSON.parse(body); | ||
const resultsFlat = results.results.map(c => ({ | ||
name: c.name[0], | ||
desc: c.description ? c.description[0] : '', | ||
})); | ||
// Return the results part of the HTTP response | ||
resolve(results.results); | ||
resolve(resultsFlat); | ||
}); | ||
}); | ||
}); | ||
|
||
module.exports = { | ||
getSearchUrl, | ||
searchPackages | ||
searchPackages, | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work on my machine for some reason...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! This is my fault. I've updated the endpoint to the secure protocol. We'll just need to require the
https
module instead ofhttp
. Feel free to send a new PR for this. 👍