babel-plugin-transform-currency-operators
Advanced tools
Comparing version 1.0.0-beta.2 to 1.0.0-beta.3
{ | ||
"name": "babel-plugin-transform-currency-operators", | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0-beta.3", | ||
"homepage": "An experimental babel plugin for transforming currency.js operators", | ||
@@ -5,0 +5,0 @@ "description": "https://github.com/scurker/babel-plugin-transform-currency-operators", |
@@ -87,4 +87,26 @@ # babel-plugin-transform-currency-operators [![Build Status](https://travis-ci.org/scurker/babel-plugin-transform-currency-operators.svg?branch=master)](https://travis-ci.org/scurker/babel-plugin-transform-currency-operators) [![Coverage Status](https://coveralls.io/repos/github/scurker/babel-plugin-transform-currency-operators/badge.svg?branch=master)](https://coveralls.io/github/scurker/babel-plugin-transform-currency-operators?branch=master) [![npm](https://img.shields.io/npm/v/babel-plugin-transform-currency-operators.svg?style=flat)](https://www.npmjs.com/package/babel-plugin-transform-currency-operators) | ||
## Advanced Usage | ||
If you have a need to customize and export currency settings as a module, you can include the path to your currency (relative from the root of your project) in your `.babelrc` plugin configuration to transform those imported module's operator along with any `currency.js` imports: | ||
> File in your project: `path/to/custom/currency.js` | ||
```javascript | ||
import currency from 'currency.js'; | ||
export default function myCustomCurrencyDefaults(value) { | ||
return currency(value, { symbol: '€', ...otherOptions }); | ||
} | ||
``` | ||
### `.babelrc` | ||
```javascript | ||
{ | ||
"plugins": ["transform-currency-operators", ['./path/to/custom/currency']] | ||
} | ||
``` | ||
## License | ||
[MIT](/license) |
@@ -0,1 +1,3 @@ | ||
import resolveRelativePath from './resolveRelativePath'; | ||
const arithmeticOperators = { | ||
@@ -134,4 +136,12 @@ '+': 'add', | ||
return { | ||
pre({ opts }) { | ||
let { filename } = opts | ||
, paths = Array.isArray(this.opts) | ||
? this.opts.map(path => resolveRelativePath(filename, path)) | ||
: []; | ||
this.currencyResolution = new Set(['currency.js', ...paths]); | ||
}, | ||
visitor: { | ||
VariableDeclarator({ node }, { opts }) { | ||
VariableDeclarator({ node }, { opts, currencyResolution }) { | ||
let { init } = node; | ||
@@ -142,3 +152,3 @@ | ||
init.callee.name === 'require' && | ||
init.arguments[0].value === 'currency.js' | ||
currencyResolution.has(init.arguments[0].value) | ||
) { | ||
@@ -152,6 +162,6 @@ opts.hasCurrency = true; | ||
ImportDeclaration({ node }, { opts }) { | ||
ImportDeclaration({ node }, { opts, currencyResolution }) { | ||
let { source, specifiers } = node; | ||
if (source.value === 'currency.js') { | ||
if (currencyResolution.has(source.value)) { | ||
let defaultImport = specifiers.find(specifier => | ||
@@ -158,0 +168,0 @@ t.isImportDefaultSpecifier(specifier) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11095
5
175
111