Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-currency-operators

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-currency-operators - npm Package Compare versions

Comparing version 1.0.0-beta.2 to 1.0.0-beta.3

src/resolveRelativePath.js

2

package.json
{
"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)

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