Money.js is a tiny (1kb) JavaScript currency conversion library for web & nodeJS
josscrowcroft.github.com
josscrowcroft.github.com
> 5.3 You agree not to access (or attempt to access) any of the Services by any means other than through the interface that is provided by Google, unless you have been specifically allowed to do so in a separate agreement with Google. You specifically agree not to access (or attempt to access) any of the Services through any automated means (including use of scripts or web crawlers) and shall ensure that you comply with the instructions set out in any robots.txt file present on the Services.
> 5.5 Unless you have been specifically permitted to do so in a separate agreement with Google, you agree that you will not reproduce, duplicate, copy, sell, trade or resell the Services for any purpose.
edit: That said - and even though we're semi off-topic - I contest that the google calculator API has no restrictions with being accessed by scripts or crawlers.
Note that their T&Cs under section 5.3 specify compliance with any 'robots.txt' file on the domains. In http://www.google.com/robots.txt, there is no mention of the /ig/calculator subdomain being prohibited to robots.
Also, under 5.5, the service isn't actually being duplicated, copied or resold.
Any thoughts on that?
I'm rewriting the scraper right now to use a different service with a more friendly TOS pending further investigation - can't afford a legal battle over this!
It's from the website of the Cloanto system and has some ideas on publicly available FX feeds.
It's not obvious (and IANAL) whether an undocumented API is "provided", but the bigger stink IMO is your re-licensing of the data. The data is unquestionably copyright Google, license unknown. I'd get rid of the license-tag: You're giving the world a license to re-distribute some data that may very well not be yours to distribute in the first place.
Finally, providing data for download in a neatly packaged format would qualify as duplicating and copying in my reading.
> Foreign currency rates provided by Citibank N.A. are displayed under licence.
Great news :) Thanks
In fact. I would venture to say one of the best indicator for the quality a library or plugin, is how well it's presented in html.
Does anyone else notice this?
[1]: in the loose sense of the word.
The homepage for this and the exchange rates API was designed in-browser, i had a lot of time on my hands thanks to two back-to-back 8 hour flights.
Naturally it's based on the HTML5 boilerplate (http://www.html5boilerplate.com) - HTML done by hand, but if there is a template service, I'd love to know about it.
The colours are mostly taken from Solarized Dark colour scheme and modified a bit: (http://ethanschoonover.com/solarized)
And the sandbox demo console is something i threw together just for this but released on github (http://josscrowcroft.github.com/javascript-sandbox-console/)
PS The robot (currencybot) came from http://robohash.org using the text 'CurrencyBot' :)
If you're doing accurate conversions on the server side, I guess I don't see the advantage to doing different conversions that yield different results on the client side.
Remember of course that any currency conversion will always carry inaccuracy, because every time money changes currency, somebody takes a cut.
I recommend using this alongside some other numbers-related library (such as accounting.js) to fix binary value rounding issues (and also for decent formatting)
Out of interest, what do you consider to be "accurate conversions on the server side"?
It's not impossible to do accurate calculations in JS, but my main point is that since the only built-in way to do math is floating point it's a bit of a minefield to go with a naive solution.
I agree with you though, that there will be the 1% of cases where something a lot more reliable is needed, but I imagine that's when you call in the CS heavyweights.
Is there any particular reason for the name 'fx', though? Seems a bit strange for a global variable name to be a two letter string that could be used relatively commonly as a variable name in browser-land.
Aside from that, I love it!
So, in our analytics application, we have multiple currencies represented in one table, the result being that we have a separate column for "currency" (next to e.g. "revenue") which is shortened to "fx".
It is definitely a potentially common global variable name though, so there's a handy `noConflict` method that can be used to assign the library to another var (eg `money`), and restore the previous global value of `fx` before moneyjs was loaded.
Eg:
var money = fx.noConflict();
// now it's `money.convert()`, and `fx` is whatever it was previously
Also, if using money.js as a node package or AMD module, you simply assign it to whatever you like: var moneyBro = require("money"); // no need for `fx`
Having said that, I think it works nicely as a namespace, if confusion can be avoided --- money.js
+++ money.js
@@ -13,6 +13,8 @@
return new fxWrapper(obj);
};
+ var NS = 'CurrencyConverter';
+
// Current version.
fx.version = '0.0.1';
@@ -122,28 +124,14 @@
// Otherwise, just add `fx` to the global object
if (typeof module !== 'undefined' && module.exports) {
module.exports = fx;
- fx.fx = fx;
+ fx[NS] = fx;
} else if (typeof define === 'function' && define.amd) {
// Return the library as an AMD module:
define([], function() {
return fx;
});
} else {
- // Use fx.noConflict to restore `fx` back to its original value before money.js loaded.
- // Returns a reference to the library's `fx` object; e.g. `var money = fx.noConflict();`
- fx.noConflict = (function(previousFx) {
- return function() {
- // Reset the value of the root's `fx` variable:
- root.fx = previousFx;
- // Delete the noConflict function:
- fx.noConflict = undefined;
- // Return reference to the library to re-assign it:
- return fx;
- };
- })(root.fx);
-
- // Declare `fx` on the root (global/window) object:
- root['fx'] = fx;
+ root[NS] = fx;
}
// Root will be `window` in browser or `global` on the server:
You can change NS to whatever you like, but I believe that this is all you need to do. Because everything internally uses the enclosed `var fx`, I don't foresee issues.And by the same author: http://josscrowcroft.github.com/accounting.js/
It guesses the most likely currency given the user's IETF language tag and a list of supported currency codes.