New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

money

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

money - npm Package Compare versions

Comparing version 0.0.1 to 0.1.2

.DS_Store

75

money.js

@@ -1,8 +0,12 @@

/**
* money.js / fx() v0.0.1
* by Joss Crowcroft, (c) 2011
*
* JavaScript library for realtime currency conversion and exchange rate calculation
* Library structure and chaining techniques borrowed from underscore.js by Jeremy Ashkenas
* For details, examples and documentation: http://josscrowcroft.github.com/money.js/
/*!
* money.js / fx() v0.1.2
* Copyright 2011, Joss Crowcroft
*
* JavaScript library for realtime currency conversion and exchange rate calculation.
*
* Freely distributable under the MIT license.
* Portions of money.js are inspired by or borrowed from underscore.js
*
* For details, examples and documentation:
* http://josscrowcroft.github.com/money.js/
*/

@@ -17,3 +21,3 @@ (function(root, undefined) {

// Current version.
fx.version = '0.0.1';
fx.version = '0.1.2';

@@ -23,7 +27,7 @@

// fxSetup can be defined before loading the money.js, to set the exchange rates and the
// base (and default from/to) currencies - or the rates can be loaded in later, as needed
// fxSetup can be defined before loading money.js, to set the exchange rates and the base
// (and default from/to) currencies - or the rates can be loaded in later if needed.
var fxSetup = root.fxSetup || {
rates : {},
base : "USD"
base : ""
};

@@ -68,21 +72,25 @@

// Returns the exchange rate to `target` currency from `base` currency
var getRate = function(target, base) {
// Save bytes in minified version:
var getRate = function(to, from) {
// Save bytes in minified version
var rates = fx.rates;
// Throw an error if either rate isn't in the rates array:
if ( !rates[base] || !rates[target] ) throw "fx error";
// Make sure the base rate is in the rates object:
rates[fx.base] = 1;
// If base currency === fx.base, return the basic exchange rate for the target currency
if ( base === fx.base ) {
return rates[target];
// Throw an error if either rate isn't in the rates array
if ( !rates[to] || !rates[from] ) throw "fx error";
// If `from` currency === fx.base, return the basic exchange rate for the `to` currency
if ( from === fx.base ) {
return rates[to];
}
// If target currency === fx.base, return the inverse rate of the base currency
if ( target === fx.base ) {
return 1 / rates[base];
// If `to` currency === fx.base, return the basic inverse rate of the `from` currency
if ( to === fx.base ) {
return 1 / rates[from];
}
// Otherwise, return the target rate multipled by the inverse of the base rate
return rates[target] * (1 / rates[base]);
// Otherwise, return the `to` rate multipled by the inverse of the `from` rate to get the
// relative exchange rate between the two currencies
return rates[to] * (1 / rates[from]);
};

@@ -94,4 +102,10 @@

// If fx(val) is called as a function, it returns a wrapped object that can be used OO-style
var fxWrapper = function(obj) {
this._v = obj;
var fxWrapper = function(val) {
// Experimental: parse strings to pull out currency code and value:
if ( typeof val === "string" ) {
this._v = parseFloat(val.replace(/[^0-9-.]/g, ""));
this._fx = val.replace(/([^A-Za-z])/g, "");
} else {
this._v = val;
}
};

@@ -127,5 +141,7 @@

// Otherwise, just add `fx` to the global object
if (typeof module !== 'undefined' && module.exports) {
module.exports = fx;
fx.fx = fx;
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = fx;
}
exports.fx = lib;
} else if (typeof define === 'function' && define.amd) {

@@ -154,2 +170,3 @@ // Return the library as an AMD module:

}(this));
// Root will be `window` in browser or `global` on the server:
}(this));

@@ -8,6 +8,6 @@ {

"contributors" : [],
"dependencies" : [],
"dependencies" : {},
"repository" : {"type": "git", "url": "git://github.com/josscrowcroft/money.js.git"},
"main" : "money.js",
"version" : "0.0.1"
"version" : "0.1.2"
}

@@ -14,7 +14,11 @@ # money.js / fx()

// And settings, allowing this:
// Basic parsing:
fx("$1.99 HKD").to("EUR");
// And simple setup, allowing this:
fx(1).convert();
// Oh yeah and nodeJS:
var fx = require('path/to/fx');
// Oh yeah and nodeJS / AMD:
var fx = require('money');
require(["money"], function(fx) { /* ... */ });
```

@@ -27,3 +31,16 @@

### 0.1.2
* Strengthened up module definition similar to accounting.js
### 0.1.1
* Add fallback in case base rate is not in rates object (e.g. `"USD": 1`) to avoid errors.
### 0.1.0
* Unexciting version number bump. Oh yeah and it has a license now.
### 0.0.2
* Adds basic parsing to `fx()`, so that you can pass a formatted string, like so: `fx("$1.99 HKD").to("GBP")`
* Some cleanup and improved comments and docs
### 0.0.1
* First release

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc