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

eos-common

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eos-common - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

index.d.ts

108

index.js
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
const decimal_js_1 = require("decimal.js");
class Symbol {
/**
* Symbol Class
*
* @param {string} symbol Symbol
* @param {number} precision Precision
* @returns {Symbol} Symbol
* @example
*
* const sym = new Symbol("EOS", 4);
* sym.symbol //=> "EOS"
* sym.precision //=> 4
*/
constructor(symbol, precision) {
this.symbol = symbol;
this.precision = precision;
}
}
exports.Symbol = Symbol;
/**
* Symbol
*
* @param {string} symbol Symbol
* @param {number} precision Precision
* @returns {Symbol} Symbol
* @example
*
* const sym = symbol("EOS", 4);
* sym.symbol //=> "EOS"
* sym.precision //=> 4
*/
function symbol(symbol, precision) {
return new Symbol(symbol, precision);
}
exports.symbol = symbol;
class Asset {
/**
* Asset Class
*
* @param {number} amount Amount (uint64_t)
* @param {Symbol} symbol Symbol
* @returns {Asset} Asset
* @example
*
* const quantity = new Asset(10000, new Symbol("EOS", 4));
* quantity.toString() //=> "1.0000 EOS";
* quantity.symbol.symbol //=> "EOS"
* quantity.symbol.precision //=> 4
*/
constructor(amount, symbol) {
this.amount = amount;
this.symbol = symbol;
}
toString() {
const amount = this.toDecimal().toFixed(this.symbol.precision);
const symbol = `${this.symbol.symbol}`;
return `${amount} ${symbol}`;
}
toDecimal() {
return new decimal_js_1.Decimal(this.amount).div(Math.pow(10, this.symbol.precision));
}
toNumber() {
return this.toDecimal().toNumber();
}
}
exports.Asset = Asset;
/**
* Asset
*
* @param {number} amount Amount (uint64_t)
* @param {Symbol} symbol Symbol
* @returns {Asset} Asset
* @example
*
* const quantity = asset(10000, new Symbol("EOS", 4));
* quantity.toString() //=> "1.0000 EOS";
* quantity.symbol.symbol //=> "EOS"
* quantity.symbol.precision //=> 4
*/
function asset(amount, symbol) {
return new Asset(amount, symbol);
}
exports.asset = asset;
/**
* Split quantity string
*
* @param {string} quantity Quantity string
* @returns {Asset}
* @example
*
* const quantity = split("1.0000 EOS");
* quantity.amount //=> 10000
* quantity.symbol.precision() //=> 4
* quantity.symbol.symbol() //=> "EOS"
*/
function split(quantity) {
const [amount, symbol] = quantity.split(" ");
const precision = (amount.split(".")[1] || []).length;
const amount_uint64 = new decimal_js_1.Decimal(amount).times(new decimal_js_1.Decimal(10).pow(precision)).toNumber();
return new Asset(amount_uint64, new Symbol(symbol, precision));
}
exports.split = split;
__export(require("./libraries/eosiolib/asset"));
__export(require("./libraries/eosiolib/symbol"));
{
"name": "eos-common",
"version": "0.1.0",
"description": "EOS common library used for Typescript",
"version": "0.1.1",
"description": "EOSIO Smart Contract common library used for Typescript",
"main": "index.js",

@@ -14,3 +14,3 @@ "types": "index.d.ts",

"scripts": {
"prepublishOnly": "tsc",
"prepublishOnly": "tsc -d",
"test": "jest --coverage",

@@ -17,0 +17,0 @@ "posttest": "tslint -p .",

@@ -1,2 +0,2 @@

# EOS common library used for Typescript
# `eos-common`

@@ -7,3 +7,3 @@ [![Build Status](https://travis-ci.org/EOS-Nation/eos-common.svg?branch=master)](https://travis-ci.org/EOS-Nation/eos-common)

> General purpose library for the DAPP network
> EOSIO Smart Contract common library used for Typescript

@@ -29,3 +29,3 @@ ## Installation

const {amount} = split("1.0000 EOS");
const { amount } = split("1.0000 EOS");
amount //=> 10000

@@ -32,0 +32,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