
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
news-wrapper
Advanced tools
[WIP] A Javascript wrapper to work with [News API] (https://newsapi.org).
$ npm install --save news-wrapper
// to import a specific method
import NewsWrapper from 'news-wrapper';
const news = new NewsWrapper({
token: 'YOUR_TOKEN_HERE'
});
// using method
const promise = news.search.topheadlines({ sources: 'cnn'});
promise.then(({ data }) => {
const markup = data.articles.map(headline => {
return `<div>${headline.title}</div>`;
});
document.getElementById('news').innerHTML = markup;
});
const NewsWrapper = require('news-wrapper').default;
const news = new NewsWrapper({
token: 'YOUR_TOKEN_HERE'
});
<!-- to import non-minified version -->
<script src="news-wrapper.umd.js"></script>
<!-- to import minified version -->
<script src="news-wrapper.umd.min.js"></script>
After that the library will be available to the Global as NewsWrapper
. Follow an example:
const news = new NewsWrapper({
token: 'YOUR_TOKEN_HERE'
});
const sources = news.search.sources({ category: 'technology'});
Follow the methods that the library provides.
This method provides live top and breaking headlines for a single source, or multiple sources. Test in npm runkit.
Arguments
Argument | Type | Options |
---|---|---|
query | string | 'Any search query' |
sources | string | 'Any source query' |
category | string | 'Any category query' |
language | string | 'Any language' |
country | string | 'Any country' |
The argument query
is optional. In case nothing is passed, the method will retrieve Techcrunch available headlines. In case more than one source is needed, you can add a string separated by commas, like 'cnn,techcrunch,bbc' for example.
Default: Techcrunch.
For more details about country
and language
supported, please check NewsAPI
Example
news.search.topheadlines({ sources: 'cnn'});
.then(({ data }) => {
// do what you want with the data
})
If you want to specify more than one source:
news.search.topheadlines({ sources: 'cnn,techcrunch,bbc' });
.then(({ data }) => {
// do what you want with the data
})
This method will get all sources available. It's possible to filter by either
category
and/orcountry
. Test in npm runkit.
Arguments
Argument | Type | Options |
---|---|---|
category | string | 'Any of the below list' |
country | string | 'Any of the below list' |
language | string | 'Any of the below list' |
Available categories: business
entertainment
gaming
general
health-and-medical
music
politics
science-and-nature
sport
technology
Default: all categories.
Available countries: ar
au
br
ca
cn
de
es
fr
gb
hk
ie
in
is
it
nl
no
pk
ru
sa
sv
us
za
Default: all countries.
Available languages: ar
en
cn
de
es
fr
he
it
nl
no
pt
ru
sv
ud
Default: all languages.
Example
news.search.sources({ category: 'technology', country: 'us' })
.then(({ data } ) => {
// do what you want with the data
})
This method retrieves all news related to the query passed in. It includes all kind of sources. Test in npm runkit.
Arguments
Argument | Type | Options |
---|---|---|
query | string | 'Any search query' |
sources | string | 'Any source query' |
from | string | 'Starting date' |
to | string | 'Ending date' |
page | int | 'Pagination number' |
The only required parameter is query, all other parameters are optional. Both from
and to
needs to be in ISO 8601 format
(e.g. 2018-01-02
or 2018-01-02T12:16:22
)
1
Example
news.search.everything({ query: 'bitcoin' })
.then(({ data }) => {
// do what you want with the data
})
news.search.everything({ query: 'bitcoin', sources: 'cnn', from: '2017-12-23', to: '2017-12-28', page: 2 })
.then(({ data }) => {
// do what you want with the data
})
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
This project is licensed under the ISC License - see the LICENSE.md file for details
FAQs
A Javascript library to work with API news
The npm package news-wrapper receives a total of 24 weekly downloads. As such, news-wrapper popularity was classified as not popular.
We found that news-wrapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.