npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adon-exchange

v1.0.9

Published

A simple currency manager from Objects - CSV - JSON - XML to mongoose model, promisified with bluebird

Downloads

2

Readme

AdOn Exchange

A simple currency manager from Objects - CSV - JSON - XML to mongoose model, promisified with bluebird.

Installing

Using npm :

npm install adon-exchange

Using yarn :

yarn add adon-exchange

Setup

Import ES6 module style :

import Exchange from 'adon-exchange'

Or CommonJS style :

const Exchange = require('adon-exchange')

Then provide a configuration object to the class constructor containing your mongoose model :

// Example Configuration

import Currency from 'path/to/models/currency'

const exchange = new Exchange(Currency)

Your model must contain at least from, to, value fields, and should contain date, modified and origin for better tracking :

// Example Currency Model

import mongoose from 'mongoose'

const { Schema } = mongoose
  , currencySchema = new Schema({
    , date: { type: Date, default: Date.now }
    , modified: { type: Date, default: Date.now }
    , origin: { type: String, default: 'automatic' }
    , from: { type: String, required: true }
    , to: { type: String, required: true }
    , value: { type: Number, required: true }
})

export default mongoose.model('Currency', currencySchema)

Useage

fileToCurrencies(options)

Assuming you already got a mongoose instance connected to MongoDB and your file uploaded somewhere in your application scope, provide a single object to the fileToCurrencies function with the following properties :

exchange.fileToCurrencies({
  file: // The path to your file
  , precision: // Opt. Float decimals, default to 6
  , origin: // Opt. Operation origin, default to 'manual'
  , delimiter: // Opt. The CSV delimiter, default to ';'
  , root: // Opt. The XML root path to lines, default to 'root.line'
})
    .then(currencies => // Do something with your currencies)
    .catch(err => // Treat errors)

createCurrency(options)

This function is called to create a new Currency and by fileToCurrencies for every lines (reverse currency is also created):

exchange.createCurrency({
  from: // Origin currency (should be a 3 letters currency code)
  , to: // Destination currency
  , value: // Conversion value
})
  .then(currencies => // Do something with your currencies)
  .catch(err => // Treat errors)

readCurrency(options)

Get a currency by its from and to properties (reverse currency is also returned) :

exchange.readCurrency({
  from: // Origin currency
  , to: // Destination currency
})
  .then(currencies => // Do something with your currencies)
  .catch(err => // Treat errors)

readCurrencies(options)

Get all currencies (without arguments) or by their from or to properties (reverse currencies are not returned) :

exchange.readCurrencies({
  from: // Opt. Origin currency
  , to: // Opt. Destination currency
})
  .then(currencies => // Do something with your currencies)
  .catch(err => // Treat errors)

updateCurrency(options)

Update currency by its from and to properties, providing a value (reverse currency is also updated) :

exchange.updateCurrency({
  from: // Origin currency
  , to: // Destination currency
  , value: // New conversion value
})
  .then(currencies => // Do something with your currencies)
  .catch(err => // Treat errors)

deleteCurrency(options)

Remove currency by its from and to properties (reverse currency is also removed) :

exchange.deleteCurrency({
  from: // Origin currency
  , to: // Destination currency
})
  .then(() => // Job Done)
  .catch(err => // Treat errors)

Behaviors

The file format is automatically detected by its extension (currently CSV, JSON and XML).

Creating, reading, updating or deleting a currency also apply the reverse operation to its counterpart.

Updating a currency also bump its modified field to Date.now().

Coming Soon

  • YAML and XLS format.

  • Reverse operation currenciesToFile.

Dependencies

  • bluebird - A full featured promise library with unmatched performance.
  • csvtojson - CSV parser to convert CSV to JSON or column arrays.
  • xml2js - Simple XML to JavaScript object converter.

License

This project is licensed under the MIT License, see the LICENSE.md file for details.