zackurben / alphavantage Goto Github PK
View Code? Open in Web Editor NEWA simple interface to the Alpha Vantage API.
License: MIT License
A simple interface to the Alpha Vantage API.
License: MIT License
Hi, @zackurben @IanMitchell @jzatt
it might be me but i cant seem to make this work...
When i call :
I get error:
bundle.js:324 Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
at bundle.js:324:32
at Object.daily (bundle.js:371:18)
at (index):522:59
(anonymous) @ bundle.js:324
(anonymous) @ bundle.js:371
(anonymous) @ (index):522
Promise.then (async)
(anonymous) @ (index):522
I cant seem to figure it out, help please
1.14.3
to 1.15.0
.This version is covered by your current version range and after updating it in your project the build failed.
prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
I was looking to contribute by starting implementation of theTechnical Indicators endpoint
found at https://www.alphavantage.co/documentation/#technical-indicators.
This work includes some additional url parameters that may muddy up the current util.url() method that already exists.
My thought was to do a small re-factor to util.url that would only take the common queryString parameters across all endpoints (which looks to be function, symbol, and interval so far). Then each of the specialized endpoints (data, performance, indicators) could have helper methods that would append on their specific params?
From there, just follow the implementation from lib/data.js.
AlphaVantage has added Digital & Crypto Cyrrencies to the API, we should add it too.
🚨 You need to enable Continuous Integration on all branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.
Since we did not receive a CI status on the greenkeeper/initial
branch, we assume that you still need to configure it.
If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/
.
We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial
branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organiszation’s settings page, under Installed GitHub Apps.
Hi.
Could you add fundamental function Earnings for api https://www.alphavantage.co/query?function=EARNINGS&symbol=IBM&apikey=demo.
6.1.0
to 6.2.0
.This version is covered by your current version range and after updating it in your project the build failed.
dotenv is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
The new version differs by 4 commits.
e1e7d57
6.2.0
1eacd53
add support for preload configuration via env vars (#355)
1f84ba1
add TypeScript types (#345)
194c98e
Fix appveyor repo badge url in readme (#347)
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
The crypto endpoint for intraday data is not available anymore, per: https://www.alphavantage.co/documentation/
Remove this feature to fix ci pipeline.
Is it possible to implement the time series search functionality?
AlphaVantage has added Foreign Exchange to the API, we should add it too.
Hi, thanks for this great job.
Experimental function make error with CSV result :
I try with :
alpha.experimental('LISTING_STATUS')
Error is :
FetchError: invalid json response body at https://www.alphavantage.co/query?apikey=XXX&function=LISTING_STATUS reason: Unexpected token s in JSON at position 0
at /node_modules/cross-fetch/node_modules/node-fetch/lib/index.js:273:32
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
type: 'invalid-json'
}
First off all :)
Very interesting library i am using it for my new website .
Thank you soooooooo much for creating it.
I don't know how to get for example the latest price for example of NIO stock
const nioPrice = await alpha.data.intraday(nio
);
for example this returns me a big object with intraday prices , i just need the latest ...
node_modules/alphavantage/index.js:3
import Util from './lib/util';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:881:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
at Module.load (internal/modules/cjs/loader.js:798:32)
at Function.Module._load (internal/modules/cjs/loader.js:711:12)
at Module.require (internal/modules/cjs/loader.js:838:19)
at require (internal/modules/cjs/helpers.js:74:18)
On time series data returned from the API, the util.polish()
routine may apply an incorrect timezone offset to the date time string when compared to the data["Meta Data"]["6. Time Zone"]
attribute returned in the raw data.
Tested on v2.3.0
Raw Response
Notice the time zone is US/Eastern
and that means the series key is 18th at 8pm Eastern time
{
"Meta Data": {
"1. Information": "Intraday (30min) open, high, low, close prices and volume",
"2. Symbol": "MSFT",
"3. Last Refreshed": "2022-07-18 20:00:00",
"4. Interval": "30min",
"5. Output Size": "Full size",
"6. Time Zone": "US/Eastern"
},
"Time Series (30min)": {
"2022-07-18 20:00:00": {
"1. open": "254.6000",
"2. high": "255.2000",
"3. low": "254.6000",
"4. close": "255.0200",
"5. volume": "7262"
},
...
}
Polished Response
Notice the series key is 18th at 7pm with a Zulu zone, or UTC. This will mean a 5 hour difference to the correct time of the data point.
{
"meta": {
"information": "Intraday (30min) open, high, low, close prices and volume",
"symbol": "MSFT",
"updated": "2022-07-18 20:00:00",
"interval": "30min",
"size": "Full size",
"zone": "US/Eastern"
},
"Time Series (30min)": {
"2022-07-18T19:00:00.000Z": {
"open": "254.6000",
"high": "255.2000",
"low": "254.6000",
"close": "255.0200",
"volume": "7262"
},
...
}
Ideally the ISO string should contain the offset to UTC, e.g. 2022-07-18T20:00:00.000-04:00
, so it can be correctly parsed.
const alpha = require('alphavantage')({ key: 'mykey' });
alpha.data.intraday("MSFT", "full", "json", "30min").then((data) => {
console.log(`data: ${JSON.stringify(data, null, 4)}`);
console.log(`polish: ${JSON.stringify(alpha.util.polish(data), null, 4)}`);
}).catch((e) => {
console.log(`e ${JSON.stringify(e, null, 4)}`)
})
Looking for way to interface this with a vue/nuxtjs app.
I keep hitting this problem where I'm not able to import alphavantage through plugins... Was wondering if there was something wrong with package.json? Thanks!
ERROR in ./node_modules/alphavantage/node_modules/dotenv/lib/main.js
Module not found: Error: Can't resolve 'fs' in '/Users/XXXXX/Projects/myApp/myApp/node_modules/alphavantage/node_modules/dotenv/lib'
ERROR in ./node_modules/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in '/Users/XXXXX/Projects/myApp/myApp/node_modules/request/lib'
/** plugins/alphavantage.js
* Init Alpha Vantage with your API key.
*
* @param {String} key
* Your Alpha Vantage API key.
*/
import AlphaVantage from 'alphavantage'
import Vue from 'vue'
const alpha = AlphaVantage({
key: '0ZC3SK0K7V1R4UZZ'
})
Vue.use(alpha)
Hi all,
I'm working on a typescript project using this nice alphavantage lib. And would be nice to have access to all param and return types.
Would be nice that this ones were exported aswell.
// https://www.alphavantage.co/documentation/#dailyadj interface RawStockDailyAdjusted { 'Meta Data': { '1. Information': string; '2. Symbol': string; '3. Last Refreshed': string; '4. Output Size': string; '5. Time Zone': string; }; 'Time Series (Daily)': { [date: string]: | { '1. open': string; '2. high': string; '3. low': string; '4. close': string; '5. adjusted close': string; '6. volume': string; '7. dividend amount': string; '8. split coefficient': string; } | undefined; }; }
Also would be nice to have this interface improved in terms of replacing the T with the correct interfaces
intraday: <T = any>(symbol: string, outputsize?: string, datatype?: string, interval?: string) => Promise<T>; daily: <T = any>(symbol: string, outputsize?: string, datatype?: string, interval?: string) => Promise<T>; daily_adjusted: ( symbol: string, outputsize?: string, datatype?: string, interval?: string ) => Promise<RawStockDailyAdjusted>;
1.0.5
to 1.0.6
.This version is covered by your current version range and after updating it in your project the build failed.
request-promise-native is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
The new version differs by 10 commits.
7ad655a
Version 1.0.6 (now really)
1240b80
fix: updated indirect lodash dependency to fix security vulnerability
80947a1
Version 1.0.6
ad529a3
chore: fix ci build for node v8+
c2c54c4
Merge pull request #33 from jasonmit/u/jasonmit/fix-node-6
67f7ed2
Merge branch 'master' into u/jasonmit/fix-node-6
4633d4c
fix: breaking change in tough-cookie v3
14aa6ee
chore: added node 8 and 10 to ci build
9cfcaaa
Update package.json
049152b
fix: target tough-cookie 2.x to preserve node 6 support
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
3.0.2
to 3.0.3
.This version is covered by your current version range and after updating it in your project the build failed.
coveralls is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
As suggested by NPM and Snyk.
The new version differs by 1 commits.
aa2519c
dependency security audit fixes from npm & snyk (#210)
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Using the base technical indicator sma
from #18, finish implementing the following indicators with test coverage:
Branch | Build failing 🚨 |
---|---|
Dependency | prettier |
Current Version | 1.7.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As prettier is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.
I recommend you give this issue a high priority. I’m sure you can resolve this 💪
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
Hi and thanks for this job.
I have the impression that intraday crypto is not supported.
alpha.cryto.intraday
does not exist.
Type definitions for each of the functions available.
Data structure returned when calling the functions.
Data structure when fetched data is polished alpha.util.polish
Part of the AlphaVantage documentation mentions some endpoints that give generic company information, I was wondering if the wrapper for these endpoints exist?
Specifically the Company Overview
, example: https://www.alphavantage.co/query?function=OVERVIEW&symbol=IBM&apikey=demo
Is there a problem with the build? I see there is a build error.
4.41.4
to 4.41.5
.This version is covered by your current version range and after updating it in your project the build failed.
webpack is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
webpack://
prefix in SourceMaps correctlyprovidedExports
with export *
which caused changing module hashes and unnecessary HMR invalidationThe new version differs by 7 commits.
45ecebc
4.41.5
8a0dac1
Merge pull request #10185 from webpack/bugfix/non-deterministic-provided-exports
4e31587
Merge pull request #10183 from webpack/deps/update
3ec952f
update dependencies in-range
8e4749e
make order of exports in providedExports deterministic
0e5e8d9
Merge pull request #10181 from webpack/backport/webpack-source-map-prefix
6b9884e
handle webpack://
prefix in SourceMap sources
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Hi,
Thanks for providing a JS wrapper around the API.
You are saying that your API calls for time series are like this:
alpha.data.intraday(symbol, outputsize, datatype, interval);
alpha.data.daily(symbol, outputsize, datatype, interval);
alpha.data.daily_adjusted(symbol, outputsize, datatype, interval);
alpha.data.weekly(symbol, outputsize, datatype, interval);
alpha.data.weekly_adjusted(symbol, outputsize, datatype, interval);
alpha.data.monthly(symbol, outputsize, datatype, interval);
alpha.data.monthly_adjusted(symbol, outputsize, datatype, interval);
alpha.data.quote(symbol, outputsize, datatype, interval);
But the fact is the only intraday
support interval
parameter. The rest of the calls the internal
is obsolete (and even an invalid request).
You could clean-up your API? And update your docs plz?
This is only very confusing for people.
Regards,
Melroy van den Berg
Branch | Build failing 🚨 |
---|---|
Dependency | jest |
Current Version | 21.0.2 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As jest is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.
I recommend you give this issue a high priority. I’m sure you can resolve this 💪
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
Branch | Build failing 🚨 |
---|---|
Dependency | prettier |
Current Version | 1.6.1 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As prettier is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.
I recommend you give this issue a high priority. I’m sure you can resolve this 💪
This release features some bugfixes and tweaks around JSX, TypeScript, CSS, and JavaScript formatting, as well as a couple new features.
We received a lot of community feedback about the changes we made to JSX formatting in the 1.6.0 release, and have made changes to bring formatting closer to community standards and expectations.
In 1.6.0, we added a second style for ternaries (conditional expressions, a ? b : c
), based on a format popular in the community where parentheses are used to demarcate JSX content:
const DinnerOptions = ({ willEatMeat, willEatEggs, willEatVegetables }) => ( <div> <div>Let's get some dinner...</div> {willEatMeat ? ( <FullMenu /> ) : willEatEggs ? ( <VegetarianMenu /> ) : willEatVegetables ? ( <VeganMenu /> ) : ( <BackupMenu /> )} </div> );
Before this was added, prettier only formatted ternaries with one consistent style:
willEatMeat ? "Full Menu" : willEatEggs ? "Vegetarian Menu" : willEatVegetables ? "Vegan Menu" : "Backup Menu";
In 1.6.0, we used the following heuristic to decide when to use the new "JSX mode ternaries":
We should print a ternary using JSX mode if:
* The ternary contains some JSX in it
OR
* The ternary appears inside of some JSX
However, this heuristic caused some unexpected formatting:
So, in 1.7.0, we have revised our heuristic to just be:
We should print a ternary using JSX mode if:
* The ternary contains some JSX in it
We hope that this change will result in fewer surprising ternaries.
A big thanks goes out to @duailibe who implemented this change in addition to several other JSX-related formatting issues that were reported.
We spent some time this release polishing our CSS formatting, and as part of that, @lydell did some work to normalize letter case.
So now, almost everything in CSS will print using lower case
.
/* Before */ DIV.Foo { HEIGHT: 12PX; }/ After /
div.Foo {
height: 12px;
}
Don't worry, though – Prettier won't touch your $scss-variables
, @less-variables
, or FunctionNames()
. Preprocess on!
There is a new option called --require-pragma
(requirePragma
via the API) which will change prettier's behavior so that it only reformats a file if it has a special "pragma" comment at the top of it, that looks like this:
/** * @prettier */
or
/** * @format */
This was @ajhyndman's idea and it was implemented by @wbinnssmith.
There was a bug in Prettier 1.6.1 where an error would be thrown while parsing any TypeScript using the never
type, for example:
Observable.empty<never>();
Also, Prettier 1.6.1 was incorrectly removing the declare
keyword from enum
declarations in *.d.ts
files:
// In declare const enum Foo {}// Out
const enum Foo {}
Both of these issues have been fixed. Thanks to @JamesHenry and @existentialism for these fixes which support our TypeScript community!
There is a new CLI option --config-precedence
which configures how prettier should prioritize config sources. Valid values are:
cli-override
(default) - CLI options take precedence over config file
file-override
- Config file take precedence over CLI options
prefer-file
- If a config file is found will evaluate it and ignore other CLI options. If no config file is found CLI options will evaluate as normal.
This option adds support to editor integrations where users define their default configuration but want to respect project specific configuration.
prettier.resolveConfig.sync
Previously, there was no way via the API to resolve configuration for a source file synchronously. Thanks to some new additions to cosmiconfig
by @sudo-suhas, @ikatyang was able to add support for this to the prettier API.
.sync()
method by @ikatyangresolveConfigFile.sync()
by @ikatyangcross-spawn
by @ikatyangfiles:
over types:
in pre-commit configuration by @asottilequery
) by @azz?:
instead of ?!
by @ikatyangdeclare
modifier from enum
reported by @mariusschulzThank you to everyone who contributed to this release, be it through issue creation, code contribution, code review, or general commenting and feedback. Prettier is a community-run project and is able to continue to exist thanks to people like you. Thank you!
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
Hey, thanks for creating this module. :) It works great for my purposes, but when I first installed it via npm install alphavantage
I couldn't require('alphavantage')
until I also manually ran npm install dotenv
. I think because your package.json
file uses index.js
as main
and index.js
requires dotenv
, shouldn't dotenv
be in dependencies
in package.json
instead of devDependencies
?
The LISTING_STATUS function returns a list in CSV format. It would be nice to be able to do that with this library.
In the docs, it shows this for an intraday request with an interval:
alpha.data.intraday(symbol, interval)
However, the following doesn't work (interval is still set to 1min):
alpha.data.intraday(symbol, '5min')
This does, however:
alpha.data.intraday(symbol, 'compact', 'json', '5min');
Perhaps a config object would make more sense here, and/or updating the docs to be clearer about this?
Also, thanks for this great library!
Similarly to #19, create a new mama
technical indicator function in lib/technical.js
and implement all the following MAMA-like indicators:
3.0.4
to 3.0.5
.This version is covered by your current version range and after updating it in your project the build failed.
coveralls is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 6 commits.
55fc4d8
Merge branch 'master' of https://github.com/nickmerwin/node-coveralls
b94fd9a
version bump
0c147a8
fix: vulnerabilities (#227)
2c73fc8
Bump lodash from 4.17.11 to 4.17.14 (#229)
cf1921d
Update configuration logic for Jenkins (#217)
f0ddec5
Add support for Azure Pipelines (#221)
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
I am unable to use the typescript interfaces for polished data (namely StockQuote
, StockDailyAdjusted
, and StockSearch
) because they aren't exported from the namespace.
Adding an export
before each of these will allow them to be used properly as the generic type <T>
when calling the util.polish()
function
e.g.
import Alphavantage from "alphavantage"
const alpha = Alphavantage({key: 'api_key'});
// ...
const polishedData = alpha.util.polish<Alphavantage.StockQuote>(rawData);
Been looking at the docs and this package to find the ability to send a startDate & endDate type of params but no api seems to support it? how would you go about specific 90 day range in 2016?
Thanks in advance!
Any chance of getting support for their historical data api? Happy to submit a PR for it!
Hi, if I'm looking to get real-time data on specific time intervals like 1 min, does this package take care of the subscription to the API or I will have to implement ?
Can I change the time zone in the result from Alpha Vantage API? Here is an example of the output. It's currently in EST. I'd like to get it in IST.
'Meta Data': {
'1. Information': 'Intraday (1min) open, high, low, close prices and volume',
'2. Symbol': 'BSE:------',
'3. Last Refreshed': '2019-11-01',
'4. Output Size': 'Compact',
'5. Time Zone': 'US/Eastern
}
'Time Series (1min)': {
'2019-11-01 00:08:59': {
'1. open': '70.7500',
'2. high': '70.7500',
'3. low': '70.7500',
'4. close': '70.7500',
'5. volume': '0'
},
I need a detailed code on how to use quotes because I keep getting a promise pending or if I use the .then function data is non existing. The Documentation on Alpha is not that great can anyone help?
3.0.6
to 3.0.7
.This version is covered by your current version range and after updating it in your project the build failed.
coveralls is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 1 commits.
2ed185c
added support for GitLab Merge Request IID
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Hi, can it query multiple symbol in one time?
symbols= ["IBM", "MSFT", "APPL"]
alpha.experimental('EARNINGS', {
symbols
}).then(data => {})
Branch | Build failing 🚨 |
---|---|
Dependency | request |
Current Version | 2.81.0 |
Type | dependency |
This version is covered by your current version range and after updating it in your project the build failed.
request is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪
The new version differs by 27 commits.
0ab5c36
2.82.0
ffdf0d3
Updating deps.
4386836
Merge branch 'master' of github.com:request/request
1527407
Merge pull request #2703 from ryysud/add-nodejs-v8-to-travis
3afcbf8
Merge branch 'master' of github.com:request/request
479143d
Update of hawk and qs to latest version (#2751)
169be11
Add Node.js v8 to Travis CI
643c43a
Fixed some text in README.md (#2658)
e8fca51
chore(package): update aws-sign2 to version 0.7.0 (#2635)
e999203
Update README to simplify & update convenience methods (#2641)
6f286c8
lint fix, PR from pre-standard was merged with passing tests
a765593
Add convenience method for HTTP OPTIONS (#2541)
52d6945
Add promise support section to README (#2605)
b12a624
refactor(lint): replace eslint with standard (#2579)
29a0b17
Merge pull request #2598 from request/greenkeeper-codecov-2.0.2
There are 27 commits in total.
See the full diff
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
Branch | Build failing 🚨 |
---|---|
Dependency | request |
Current Version | 2.82.0 |
Type | dependency |
This version is covered by your current version range and after updating it in your project the build failed.
request is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
Similarly to #19, create a new macd
technical indicator function in lib/technical.js
and implement all the following MACD-like indicators:
devDependency
@babel/core was updated from 7.7.7
to 7.8.0
.devDependency
@babel/preset-env was updated from 7.8.0
to 7.8.2
.This version is covered by your current version range and after updating it in your project the build failed.
This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.
babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Recently AlphaVantage has added a new API function TIME_SERIES_INTRADAY_EXTENDED
, see: https://www.alphavantage.co/documentation/#intraday-extended
Can you please add this?
It would be preferred to have the optional parameter adjusted
in as well. Also for TIME_SERIES_INTRADAY
, which is currently lacking in alpha.data.intraday(symbol, outputsize, datatype, interval)
Thank you in advance.
Branch | Build failing 🚨 |
---|---|
Dependency | prettier |
Current Version | 1.5.3 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As prettier is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.
I recommend you give this issue a high priority. I’m sure you can resolve this 💪
I want to give a special shout out to @azz who has been maintaining the repository and implementing a bunch of the changes in this release as I had less time to devote to prettier due to vacation and switching team :)
Since the very first release of prettier, people have asked for a .prettierrc
file. We've been trying to have as few options as possible and tried to avoid being one more .dotfile
that you have to have when starting a new project.
But, the truth is, we need to have some way to configure prettier that can be kept in sync with all the integrations. By not having one, we pushed the problem to them and saw a bunch of incompatible ways of handling the problem. So now, it's handled by prettier itself.
// .prettierrc { "trailingComma": "es5", "singleQuote": true }
For more information on configuration file support, see the README.
Along with telling what configuration to use, you can write a file .prettierignore
to tell which files not to convert.
# .prettierignore
dist/
package.json
The last big friction point from people trying to adopt prettier was around how JSX was being printed. We went through all the issues that were raised and made a bunch of changes:
// Before const Component = props => <div> Hello {props.name}! </div>;// After
const Component = props => (
<div>
Hello {props.name}!
</div>
);
// Before <div> {props.isVisible ? <BaseForm url="/auth/google" method="GET" /> : <Placeholder />} </div>;// After
<div>
{props.isVisible ? (
<BaseForm
url="/auth/google"
method="GET"
/>
) : (
<Placeholder />
)}
</div>
// Before <div> {props.isVisible && <BaseForm url="/auth/google" method="GET" />} </div>;// After
<div>
{props.isVisible && (
<BaseForm
url="/auth/google"
method="GET"
/>
)}
</div>
Hopefully this is going to be more in line with how the majority of the community is writing JSX and we can have prettier be used in more place ;)
With JSX, we started by respecting a lot of line breaks that were in the original source. This had the advantage of doing fewer changes to your codebase but chipped away the value of a consistent pretty printer as the same semantic code could be written in two ways.
During each new release we've tightened this and made decisions around how to always print a piece of code. The latest of those is what happens if there's a single child in a JSX object, we're now always going to inline it.
// Before return ( <div> {this.props.test} </div> ); return <div>{this.props.test}</div>;// After
return <div>{this.props.test}</div>;
return <div>{this.props.test}</div>;
Leading JSX empty spaces are now on their own line. It looked weird to have them before a tag as it "indented" it differently compared to the rest.
// Before <span className="d1"> {' '}<a href="https://github.schibsted.io/finn/troika" className="link" /> </span>// After
<span className="d1">
{' '}
<a
href="https://github.schibsted.io/finn/troika"
className="link"
/>
</span>
We used to use a strict JSON parser that would throw if there was a comment or a trailing comma. This was inconvenient as many JSON files in practice are parsed using JavaScript or json5 that are not as strict. Now, we have relaxed this and are using the JavaScript parser to parse and print JSON. This means that comments will be maintained if there were some.
Note that this is purely additive, if your original file was JSON compliant, it will keep printing a valid JSON.
// Before Syntax error// After
{ / some comment / "a": 1 }
Parenthesis are a hot topic because they are not part of the AST, so prettier ignores all the ones you are putting and re-creating them from scratch. We went through all the things that people reported and came up with a few edge cases that were very confusing when comparisons were chained and %
was mixed with *
or /
.
One thing that we are not changing is the fact that we remove extra parenthesis around combinations of basic arithmetic operators: +-*/
.
// Before x !== y === z; x * y % z;// After
(x !== y) === z;
(x * y) % z;
It's useful to be able to ignore pieces of JSX, it's now possible to add a comment inside of a JSX expression to ignore the formatting of the next element.
// Before <Component> {/*prettier-ignore*/} <span ugly format="" /> </Component>// Before
<Component>
{/prettier-ignore/}
<span ugly format='' />
</Component>
In order to support some edge cases, in the internals, we have the ability to avoid printing comments in a generic way and print them in the call site instead. It turns out that when we used prettier-ignore
, we didn't print the comments at all! This is now fixed.
// Before push( <td> :) </td>, );// After
push(
// prettier-ignore
<td> :)
</td>,
);
It took 6 months for someone to report that do-while were broken when the while condition is multi-line, it confirms my hunch that this construct is not widely used in practice.
// Before do {} while ( someVeryLongFunc( someVeryLongArgA, someVeryLongArgB, someVeryLongArgC ) );// After
do {} while (
someVeryLongFunc(
someVeryLongArgA,
someVeryLongArgB,
someVeryLongArgC
)
);
Another underused feature of JavaScript is sequence expressions. We used to do a bad job at printing them when they would go multi-line, this has been corrected :)
// Before (a = b ? c : "lllllllllllllllllllllll"), (a = b ? c : "lllllllllllllllllllllll"), (a = b ? c : "lllllllllllllllllllllll"), (a = b ? c : "lllllllllllllllllllllll"), (a = b ? c : "lllllllllllllllllllllll");// After
(a = b ? c : 'lllllllllllllllllllllll'),
(a = b ? c : 'lllllllllllllllllllllll'),
(a = b ? c : 'lllllllllllllllllllllll'),
(a = b ? c : 'lllllllllllllllllllllll'),
(a = b ? c : 'lllllllllllllllllllllll')
We took the stance with prettier to remove all the trailing whitespaces. We used to not touch comments because it's user generated, but that doesn't mean that they should have whitespace :)
// Before // There is some space here ->______________// After
// There is some space here ->
Our handling for comments inside of the class declaration was very naive, we would just move all the comments to the top. We now are more precise and respect the comments that are interleaved inside of decorators and around extends
.
// Before // A // B // C @Foo() @Bar() class Bar {}// After
// A
@Foo()
// B
@Bar()
// C
class Bar {}
Bind expressions are being discussed at TC39 and we figured we could print it with prettier. We used to be very naive about it and just chain it. Now, we use the same logic as we have for method chaining with the .
operator for it. We also fixed some edge cases where it would output invalid code.
// Before observable::filter(data => data.someTest)::throttle(() => interval(10)::take(1)::takeUntil(observable::filter(data => someOtherTest)) )::map(someFunction);// After
observable
::filter(data => data.someTest)
::throttle(() =>
interval(10)::take(1)::takeUntil(observable::filter(data => someOtherTest))
)
::map(someFunction);
It's being discussed at TC39 to be able to make the argument of a catch(e)
optional. Let's make sure we can support it in prettier if people use it.
// Before Syntax error// After
try {} catch {}
Another new proposal being discussed at TC39 is an optional chaining syntax. This is currently a stage 1 proposal, so the syntax may change at any time.
obj?.prop // optional static property access obj?.[expr] // optional dynamic property access func?.(...args) // optional function or method call
Comments are tricky to get right, but especially when they have meaning based on where they are positioned. We're now special casing the way we deal with comments used as type cast for Closure Compiler such that they keep having the same semantics.
// Before let assignment /** @type {string} */ = getValue();// After
let assignment = /** @type {string} */ (getValue());
It looks kind of odd to have a computed property lookup on the next line, so we added a special case to inline it.
// Before data [key]('foo') .then(() => console.log('bar')) .catch(() => console.log('baz'));// After
data[key]('foo')
.then(() => console.log('bar'))
.catch(() => console.log('baz'));
The flow team introduced two very exciting features under a new syntax. We now support them in prettier. I've personally been waiting for opaque types for a veerrryyyy long time!
// Before Syntax error// After
opaque type ID = string;
export type * from "module";
We've been doing this on JavaScript objects since the early days of prettier but forgot to apply the same thing to Flow and TypeScript types.
// Before type A = { "string": "A"; }// After
type A = {
string: "A";
}
Oopsy, we were dropping the generic in this very specific case.
// Before type myFunction = A => B;// After
type myFunction = <T>(A) => B;
Parenthesis... someday we'll get all of them fixed :)
// Before const actionArray: () => void[] = [];// After
const actionArray: (() => void)[] = [];
TypeScript 2.5 RC was recently announced, allowing you to use the upcoming "optional catch binding" syntax in TypeScript, too. 🎉
// Before namespace global { export namespace JSX { } }// After
global {
export namespace JSX {}
}
Thanks to the untyped and permissive nature of JavaScript, we've been able to concat undefined to a string and get some interesting code as a result. Now fixed for this case :)
// Before <undefined.Author />// After
<this.Author />
We want to make sure that all the special cases that we added for JavaScript and Flow also work for TypeScript constructs. In this case, objects should also hug if they are wrapped in a as
operator.
// Before const state = JSON.stringify( { next: window.location.href, nonce, } as State );// After
const state = JSON.stringify({
next: window.location.href,
nonce,
} as State);
Most of the time we add parenthesis for correctness but in this case, we added them for nothing, so we can just get rid of them and have a cleaner code :)
// Before (<x>a) || {};// After
<x>a || {};
Yet another case of missing parenthesis. Thankfully we're getting very few of them nowadays and they are for extremely rare edge cases.
// Before foo.bar as Baz = [bar];// After
(foo.bar as Baz) = [bar];
The declare
keyword doesn't do anything for interface
so we never put it there. However, it felt weird if you were in a declaration file and seeing everything have declare
before it except for interfaces. So now we reprint declare
if it was there in the first place.
// Before interface Dictionary<T> { [index: string]: T }// After
declare interface Dictionary<T> {
[index: string]: T
}
In order to get a first version of CSS to ship, we kept string quotes as is. We are now respecting the singleQuote
option of prettier. The difficulty here was to make sure that we output correct code for all the crazy escapes, unicode characters, emoji, special rules like charset which only work with double quotes...
// Before div { content: "abc"; }// After
div {
content: 'abc';
}
Another place where we can reuse the logic we've done for JavaScript to improve CSS printing.
// Before border: 1px solid rgba(0., 0.0, .0, .3);// After
border: 1px solid rgba(0, 0, 0, 0.3);
I can never quite remember the rules behind quotes around attributes so we're now always putting quotes there.
// Before a[id=test] {}// After
a[id="test"] {}
// Before const header = css`.top-bar {background: black;margin: 0;position: fixed;}`// After
const header = css</span></span> <span class="pl-s"> .top-bar {</span> <span class="pl-s"> background: black;</span> <span class="pl-s"> margin: 0;</span> <span class="pl-s"> position: fixed;</span> <span class="pl-s"> }</span> <span class="pl-s"><span class="pl-pds">
;
styled-components has a lot of different variants for tagging template literals as CSS. It's not ideal that we've got to encode all those ways inside of prettier but since we started, might as well do it for real.
styled(ExistingComponent)` css: property; `;styled.button.attr({})
</span></span> <span class="pl-s"> border: rebeccapurple;</span> <span class="pl-s"><span class="pl-pds">
;
The CSS parsers we use do not give us a 100% semantic tree: in many occasions they bail and just give us what is being entered. It's up to us to make sure we clean this up while maintaining correctness. In this case, we just printed spaces between selectors as is but we know it's correct to always replace it by a single space.
// Before .hello.<span class="pl-smi">how</span><span class="pl-k">-</span>you<span class="pl-k">-</span>doin {
height: 42;
}// After
.hello .how-you-doin {
height: 42;
}Strip BOM before parsing (#2373) by @azz
I still have nightmares from dealing with BOM in a previous life. Thankfully, in 2017 it's no longer a big issue as most tooling is now aware of it. Thanks @azz for fixing an edge cases related to CSS parsing.
// Before [BOM]/* Block comment * html { content: "#{1}"; }// After [BOM]/* Block comment */ html { content: "#{1}"; }GraphQL
Add support for range-formatting GraphQL (#2319) by @josephfrazier
If you tried to use the range formatting feature in a GraphQL file, it would throw an exception, now it properly worked again and only reformats the piece you selected.
Add
.gql
file extension to be parsed as GraphQL (#2357) by @rrdelaneyAt Facebook, we use
.graphql
extension but it looks like it's common to have.gql
as well, doesn't cost a lot to support it in the heuristic that figures out what parser to use.CLI
Support multiple patterns with ignore pattern (#2356) by @evilebottnawi
It was already possible to have multiple glob patterns but they would be additive, with this change, you can add a glob pattern to ignore some files. It should be very handy to ignore folders that are deeply nested.
prettier --write '{**/*,*}.{js,jsx,json}' '!vendor/**'Make --list-different to work with --stdin (#2393) by @josephfrazier
This is a handy way of knowing if prettier would print a piece of code in a different way. We already had all the concepts in place, we just needed to wire them up correctly.
$ echo 'call ( ) ;' | prettier --list-different (stdin) $ echo $? 1Not sure how things should work exactly?
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
1.14.2
to 1.14.3
.This version is covered by your current version range and after updating it in your project the build failed.
prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.