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

@crypti/ccoin

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@crypti/ccoin - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

profiles.json

124

cli.js
#!/usr/bin/env node
/* eslint brace-style:0 */
'use strict';

@@ -6,2 +7,5 @@ const meow = require('meow');

const chalk = require('chalk');
const empty = require('is-empty');
const profiles = require('./profiles.json');
const saveProfile = require('./bin/save-profile');
const ccoin = require('.');

@@ -14,7 +18,14 @@

Usage
$ ccoin -f=[fromSymbols] -t=[toSymbols]
$ ccoin [Commands]
$ ccoin -f=[fromSymbols] -t=[toSymbols] [options]
Commands
ls List all saved profiles
[profile name] Load the given profile by name
Options
-f, --from A comma-delimited list of symbols to convert from
-t, --to A comma-delimited list of symbols to convert to
-f, --from A comma-delimited list of symbols to convert from
-t, --to A comma-delimited list of symbols to convert to
-s, --save Save this as a named profile
-d, --set-default Set this as the default profile

@@ -27,3 +38,5 @@ Examples

f: 'from',
t: 'to'
t: 'to',
s: 'save',
d: 'set-default'
}

@@ -34,26 +47,101 @@ });

const flags = cli.flags;
const profileNames = Object.keys(profiles);
if (input.length > 0 && Object.keys(flags).length > 0) {
console.log(chalk.magenta('Error:'), 'Remove all spaces in your comma-delimited lists.');
// User has supplied a valid profile name, so let's load the profile.
if (input && profileNames.indexOf(input.toString()) > -1) {
load(profiles[input].from, profiles[input].to);
}
// List the profiles
else if (input && input[0] === 'ls') {
console.log(chalk.magenta('Available Profiles:'));
profileNames.forEach(name => {
const profile = profiles[name];
const line = `-f=${profile.from} -t=${profile.to}`;
console.log(` ${chalk.cyan(name)}: ${chalk.gray(line)}`);
});
}
// You cannot set a profile name using reserved command names
else if (flags.save && flags.save === 'ls') {
console.log(chalk.magenta('Error:'), `${chalk.yellow('ls')} is a reserved command, you cannot create a profile with that name.`);
process.exit(1);
}
if (!flags || Object.keys(flags).length === 0 || !flags.from || !flags.to) {
// Set the default profile with the `--set-default` option
else if (flags.to && flags.from && flags.d) {
const {from, to} = flags;
const save = 'default';
const spinner = ora('Saving profile');
spinner.start();
saveProfile(save, from, to).then(() => {
spinner.succeed(`Saved profile ${chalk.yellow(save)}`);
load(from, to);
});
}
// Show an error when not enough information for the `--set-default` option
else if ((!flags.to || !flags.from) && flags.d) {
console.log(chalk.magenta('Error:'), `You must supply ${chalk.yellow('--from')} and ${chalk.yellow('--to')} flags in order to set a default.`);
process.exit(1);
}
// If no options or inputs are supplied, but there is
// a `default` profile, then load the default profile
else if (empty(input) && empty(flags) && profileNames.indexOf('default') > -1) {
load(profiles.default.from, profiles.default.to);
}
// Show an error and quit when attempting to save a
// profile without --from and --to flags supplied
else if (flags.save && (!flags.to || !flags.from)) {
console.log(chalk.magenta('Error:'), `You must supply ${chalk.yellow('--from')} and ${chalk.yellow('--to')} flags in order to save a profile.`);
process.exit(1);
}
// Save the profile when `--save-as` is called, then run ccoin
else if (flags.save && flags.to && flags.from) {
const {save, from, to} = flags;
const spinner = ora('Saving profile');
spinner.start();
saveProfile(save, from, to).then(() => {
spinner.succeed(`Saved profile ${chalk.yellow(save)}`);
load(from, to);
});
}
// Default API
else if (flags.from && flags.to && empty(input)) {
load(flags.from, flags.to);
}
// If no flags or input has been supplied, show the help
else if (empty(flags) && empty(input)) {
cli.showHelp();
}
spinner.start();
/**
* Run ccoin with the given from and to parameters.
* @param {string} from comma-delimited list to convert from
* @param {string} to comma-delimited list to convert to
*/
function load(from, to) {
spinner.start();
ccoin(flags.from, flags.to)
.then(prices => {
spinner.stop();
ccoin(from, to)
.then(prices => {
spinner.stop();
Object.keys(prices).forEach(from => {
console.log(`${chalk.cyan(from)} ⇒`);
prices[from].forEach((price, index) => {
const parts = price.split(':');
const left = index === prices[from].length - 1 ? '└─' : '├─';
console.log(`${chalk.gray(left)} ${chalk.yellow(parts[0])}${parts[1]}`);
Object.keys(prices).forEach(from => {
console.log(`${chalk.cyan(from)} ⇒`);
prices[from].forEach((price, index) => {
const parts = price.split(':');
const left = index === prices[from].length - 1 ? '└─' : '├─';
console.log(`${chalk.gray(left)} ${chalk.yellow(parts[0])}${parts[1]}`);
});
});
});
});
}

6

package.json
{
"name": "@crypti/ccoin",
"version": "0.1.1",
"version": "0.2.0",
"description": "Convert and fetch the cost of cryptocurrencies within your terminal",

@@ -28,3 +28,4 @@ "license": "MIT",

"index.js",
"cli.js"
"cli.js",
"profiles.json"
],

@@ -44,2 +45,3 @@ "keywords": [

"cryptocompare": "^0.1.0",
"is-empty": "^1.2.0",
"meow": "^3.7.0",

@@ -46,0 +48,0 @@ "no-whitespace": "^1.0.0",

@@ -17,7 +17,14 @@ # ccoin [![Build Status](https://travis-ci.org/crypti/ccoin.svg?branch=master)](https://travis-ci.org/crypti/ccoin) [![Coverage Status](https://coveralls.io/repos/github/crypti/ccoin/badge.svg?branch=master)](https://coveralls.io/github/crypti/ccoin?branch=master)

Usage
$ ccoin -f=[fromSymbols] -t=[toSymbols]
$ ccoin [Commands]
$ ccoin -f=[fromSymbols] -t=[toSymbols] [options]
Commands
ls List all saved profiles
[profile name] Load the given profile by name
Options
-f, --from A comma-delimited list of symbols to convert from
-t, --to A comma-delimited list of symbols to convert to
-f, --from A comma-delimited list of symbols to convert from
-t, --to A comma-delimited list of symbols to convert to
-s, --save Save this as a named profile
-d, --set-default Set this as the default profile

@@ -29,4 +36,57 @@ Examples

**Tip:** For a list of 3-letter symbols you can use with this module see [cryptocurrencies](https://github.com/radiovisual/cryptocurrencies).
**Tip:** For a list of 3-letter symbols you can use with this module see [cryptocurrencies](https://github.com/crypti/cryptocurrencies).
## Profiles
Profiles are a handy way to save `--from` and `--to` options without having to type
them manually everytime.
### To Save a Profile
Use the `--save` option or `-s` flag to save a profile by name (both examples are equivalent):
```
$ ccoin -f=BTC,ETH -t=USD,JPY --save=yen
$ ccoin -f=BTC,ETH -t=USD,JPY -s=yen
```
### To Load a Profile
Once you have a profile saved, you can just call it by name:
```
$ ccoin yen
```
### To List All Available Profiles
Use the `ls` command to list all your available Profiles:
```
$ ccoin ls
Available Profiles:
yen: -f=BTC,ETH -t=USD,JPY
```
### To Set a Default Profile
You can set a default profile with the `--set-default` option or the `-d` flag (both examples are equivalent):
```
$ ccoin -f=BTC,ETH -t=USD,JPY -d
$ ccoin -f=BTC,ETH -t=USD,JPY --set-default
```
### To Load the Default Profile
If you have a default profile set, then you don't have to do anything, you can just type
`ccoin` at the terminal and your default profile will be loaded. However, you can also
load the default profile by name, so both of these examples will load the default profile
(if one has been supplied):
```
$ ccoin
$ ccoin default
```
## Related

@@ -33,0 +93,0 @@

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