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.4.0 to 0.4.1

dist/eosiolib/symbol_code.d.ts

16

CHANGES.md

@@ -1,3 +0,15 @@

## 2020-01-24
## TO-DO
- add support for `new Asset("1.0000 EOS")`
- add test cases for `Symbol`
## 2020-02-25
- add `symbol_code` unit tests from C++ tests
- add `symbol` method
- add `symbol_code` method
- fix 7 character symcode
- fully refactor `Symbol` to C++ represenation
## 2020-02-24
- `toNumber` => `to_double`

@@ -7,2 +19,2 @@ - `toString` => `to_string`

- remove `decimal.js` dependency
- added rollup for browser bundling
- added rollup for browser bundling

57

dist/eosiolib/symbol.d.ts

@@ -1,17 +0,4 @@

/**
* @class Stores the symbol code
* @brief Stores the symbol code as a uint64_t value
*/
export declare class symbol_code {
private value;
constructor(str?: number | string);
raw(): number;
length(): number;
to_string(): string;
is_valid(): boolean;
isEqual(comparison: symbol_code): boolean;
}
import { SymbolCode } from "./symbol_code";
export declare class Symbol {
_precision: number;
private _code;
value: BigInt;
/**

@@ -30,6 +17,40 @@ * Symbol

*/
constructor(code: string | symbol_code, precision: number);
code(): symbol_code;
constructor(sc?: string | SymbolCode | number | BigInt, precision?: number);
/**
* Is this symbol valid
*/
is_valid(): boolean;
/**
* This symbol's precision
*/
precision(): number;
/**
* Returns representation of symbol name
*/
code(): SymbolCode;
/**
* Returns uint64_t repreresentation of the symbol
*/
raw(): BigInt;
isTruthy(): boolean;
isFalsy(): boolean;
/**
* Equivalency operator. Returns true if a == b (are the same)
*
* @return boolean - true if both provided symbols are the same
*/
isEqual(comparison: Symbol): boolean;
precision(): number;
/**
* Inverted equivalency operator. Returns true if a != b (are different)
*
* @return boolean - true if both provided symbols are not the same
*/
isNotEqual(comparison: Symbol): boolean;
/**
* Less than operator. Returns true if a < b.
* @brief Less than operator
* @return boolean - true if symbol `a` is less than `b`
*/
isLessThan(comparison: Symbol): boolean;
}
export declare function symbol(sc?: number | string | SymbolCode, precision?: number): Symbol;
export * from "./eosiolib/asset";
export * from "./eosiolib/check";
export * from "./eosiolib/symbol";
export * from "./eosiolib/symbol_code";
export * from "./eosiolib/time";
export * from "./eosiolib/utils";
export * from "./eosiolib/voting";

@@ -18,3 +18,2 @@ // https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/core/eosio/check.hpp

// https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp
function str_to_symbol_code(str) {

@@ -32,7 +31,7 @@ let value = BigInt(0);

}
return Number(value);
return BigInt(value);
}
function write_as_string(value) {
const mask = BigInt(0x00000000000000FF);
if (value == 0)
if (value == BigInt(0))
return '';

@@ -52,11 +51,11 @@ let begin = "";

*/
class symbol_code {
class SymbolCode {
// constructor()
constructor(str) {
this.value = 0; // uint64_t
this.value = BigInt(0);
if (str) {
if (typeof str == 'number')
this.value = Number(str);
else
if (typeof str == "string")
this.value = str_to_symbol_code(str);
else if (typeof str == "number" || typeof str == 'bigint')
this.value = BigInt(str);
}

@@ -67,2 +66,8 @@ }

}
isTruthy() {
return this.value != BigInt(0);
}
isFalsy() {
return this.value == BigInt(0);
}
length() {

@@ -78,15 +83,15 @@ let sym = BigInt(this.value);

to_string() {
return write_as_string(this.value);
return write_as_string(BigInt(this.value));
}
is_valid() {
let sym = BigInt(this.value);
for (let i = 0; i < 7; i++) {
const c = String.fromCharCode(Number(sym) & 0xFF);
for (let i = BigInt(0); i < 7; i++) {
const c = String.fromCharCode(Number(BigInt(sym) & BigInt(0xFF)));
if (!("A" <= c && c <= "Z"))
return false;
sym >>= BigInt(8);
if (!(Number(sym) & 0xFF)) {
if (!(BigInt(sym) & BigInt(0xFF))) {
do {
sym >>= BigInt(8);
if ((Number(sym) & 0xFF))
if ((BigInt(sym) & BigInt(0xFF)))
return false;

@@ -99,6 +104,39 @@ i++;

}
/**
* Equivalency operator. Returns true if a == b (are the same)
*
* @return boolean - true if both provided symbol_codes are the same
*/
isEqual(comparison) {
return comparison.value === this.value;
}
/**
* Inverted equivalency operator. Returns true if a != b (are different)
*
* @return boolean - true if both provided symbol_codes are not the same
*/
isNotEqual(comparison) {
return comparison.value !== this.value;
}
/**
* Less than operator. Returns true if a < b.
* @brief Less than operator
* @return boolean - true if symbol_code `a` is less than `b`
*/
isLessThan(comparison) {
return this.value < comparison.value;
}
}
function symbol_code(str) {
return new SymbolCode(str);
}
// (() => {
// const symcode = symbol_code(BigInt(18367622009667905n))
// console.log(symcode);
// console.log(symcode.raw());
// console.log(symcode.is_valid());
// console.log(symcode.to_string());
// })();
// https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp
class Symbol {

@@ -118,16 +156,87 @@ /**

*/
constructor(code, precision) {
this._code = (typeof code == "string") ? new symbol_code(code) : code;
this._precision = precision;
constructor(sc, precision) {
this.value = BigInt(0);
if (sc != undefined)
check(precision != undefined, "[precision] is required");
if (typeof sc == "string" && precision) {
const symcode = new SymbolCode(sc).raw();
this.value = BigInt(symcode) << BigInt(8) | BigInt(precision);
}
else if (typeof sc == "number" || typeof sc == "bigint") {
this.value = BigInt(sc);
}
else if (typeof sc == typeof SymbolCode) {
const symcode = sc;
this.value = BigInt(symcode.raw() << 8 | Number(precision));
}
}
/**
* Is this symbol valid
*/
is_valid() {
return this.code().is_valid();
}
/**
* This symbol's precision
*/
precision() {
return Number(BigInt(this.value) & BigInt(0x00000000000000FF));
}
/**
* Returns representation of symbol name
*/
code() {
return this._code;
return new SymbolCode(Number(this.value) >> 8);
}
/**
* Returns uint64_t repreresentation of the symbol
*/
raw() {
return this.value;
}
isTruthy() {
return this.value != BigInt(0);
}
isFalsy() {
return this.value == BigInt(0);
}
/**
* Equivalency operator. Returns true if a == b (are the same)
*
* @return boolean - true if both provided symbols are the same
*/
isEqual(comparison) {
return comparison.code === this.code && comparison.precision() === this.precision();
return comparison.value === this.value;
}
precision() {
return this._precision;
/**
* Inverted equivalency operator. Returns true if a != b (are different)
*
* @return boolean - true if both provided symbols are not the same
*/
isNotEqual(comparison) {
return comparison.value !== this.value;
}
/**
* Less than operator. Returns true if a < b.
* @brief Less than operator
* @return boolean - true if symbol `a` is less than `b`
*/
isLessThan(comparison) {
return this.value < comparison.value;
}
}
function symbol(sc, precision) {
return new Symbol(sc, precision);
}
// (() => {
// console.log(typeof new SymbolCode)
// console.log(typeof new SymbolCode("EOS"))
// console.log(symbol("A", 4).raw());
// console.log(symbol("AB", 4).raw());
// console.log(symbol("ABC", 4).raw());
// console.log(symbol("ABCD", 4).raw());
// console.log(symbol("ABCDE", 4).raw());
// console.log(symbol("ABCDEF", 4).raw());
// console.log(symbol("ABCDEFG", 4).raw());
// })();

@@ -257,3 +366,3 @@ // import { Decimal } from "decimal.js";

export { Asset, Symbol, asset_to_double, block_timestamp_epoch, check, current_time_point, double_to_asset, seconds_per_day, split, stake2vote, symbol_code, vote2stake, voteWeightToday };
export { Asset, Symbol, SymbolCode, asset_to_double, block_timestamp_epoch, check, current_time_point, double_to_asset, seconds_per_day, split, stake2vote, symbol, symbol_code, vote2stake, voteWeightToday };
//# sourceMappingURL=index.es.js.map

@@ -22,3 +22,2 @@ 'use strict';

// https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp
function str_to_symbol_code(str) {

@@ -36,7 +35,7 @@ let value = BigInt(0);

}
return Number(value);
return BigInt(value);
}
function write_as_string(value) {
const mask = BigInt(0x00000000000000FF);
if (value == 0)
if (value == BigInt(0))
return '';

@@ -56,11 +55,11 @@ let begin = "";

*/
class symbol_code {
class SymbolCode {
// constructor()
constructor(str) {
this.value = 0; // uint64_t
this.value = BigInt(0);
if (str) {
if (typeof str == 'number')
this.value = Number(str);
else
if (typeof str == "string")
this.value = str_to_symbol_code(str);
else if (typeof str == "number" || typeof str == 'bigint')
this.value = BigInt(str);
}

@@ -71,2 +70,8 @@ }

}
isTruthy() {
return this.value != BigInt(0);
}
isFalsy() {
return this.value == BigInt(0);
}
length() {

@@ -82,15 +87,15 @@ let sym = BigInt(this.value);

to_string() {
return write_as_string(this.value);
return write_as_string(BigInt(this.value));
}
is_valid() {
let sym = BigInt(this.value);
for (let i = 0; i < 7; i++) {
const c = String.fromCharCode(Number(sym) & 0xFF);
for (let i = BigInt(0); i < 7; i++) {
const c = String.fromCharCode(Number(BigInt(sym) & BigInt(0xFF)));
if (!("A" <= c && c <= "Z"))
return false;
sym >>= BigInt(8);
if (!(Number(sym) & 0xFF)) {
if (!(BigInt(sym) & BigInt(0xFF))) {
do {
sym >>= BigInt(8);
if ((Number(sym) & 0xFF))
if ((BigInt(sym) & BigInt(0xFF)))
return false;

@@ -103,6 +108,39 @@ i++;

}
/**
* Equivalency operator. Returns true if a == b (are the same)
*
* @return boolean - true if both provided symbol_codes are the same
*/
isEqual(comparison) {
return comparison.value === this.value;
}
/**
* Inverted equivalency operator. Returns true if a != b (are different)
*
* @return boolean - true if both provided symbol_codes are not the same
*/
isNotEqual(comparison) {
return comparison.value !== this.value;
}
/**
* Less than operator. Returns true if a < b.
* @brief Less than operator
* @return boolean - true if symbol_code `a` is less than `b`
*/
isLessThan(comparison) {
return this.value < comparison.value;
}
}
function symbol_code(str) {
return new SymbolCode(str);
}
// (() => {
// const symcode = symbol_code(BigInt(18367622009667905n))
// console.log(symcode);
// console.log(symcode.raw());
// console.log(symcode.is_valid());
// console.log(symcode.to_string());
// })();
// https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp
class Symbol {

@@ -122,16 +160,87 @@ /**

*/
constructor(code, precision) {
this._code = (typeof code == "string") ? new symbol_code(code) : code;
this._precision = precision;
constructor(sc, precision) {
this.value = BigInt(0);
if (sc != undefined)
check(precision != undefined, "[precision] is required");
if (typeof sc == "string" && precision) {
const symcode = new SymbolCode(sc).raw();
this.value = BigInt(symcode) << BigInt(8) | BigInt(precision);
}
else if (typeof sc == "number" || typeof sc == "bigint") {
this.value = BigInt(sc);
}
else if (typeof sc == typeof SymbolCode) {
const symcode = sc;
this.value = BigInt(symcode.raw() << 8 | Number(precision));
}
}
/**
* Is this symbol valid
*/
is_valid() {
return this.code().is_valid();
}
/**
* This symbol's precision
*/
precision() {
return Number(BigInt(this.value) & BigInt(0x00000000000000FF));
}
/**
* Returns representation of symbol name
*/
code() {
return this._code;
return new SymbolCode(Number(this.value) >> 8);
}
/**
* Returns uint64_t repreresentation of the symbol
*/
raw() {
return this.value;
}
isTruthy() {
return this.value != BigInt(0);
}
isFalsy() {
return this.value == BigInt(0);
}
/**
* Equivalency operator. Returns true if a == b (are the same)
*
* @return boolean - true if both provided symbols are the same
*/
isEqual(comparison) {
return comparison.code === this.code && comparison.precision() === this.precision();
return comparison.value === this.value;
}
precision() {
return this._precision;
/**
* Inverted equivalency operator. Returns true if a != b (are different)
*
* @return boolean - true if both provided symbols are not the same
*/
isNotEqual(comparison) {
return comparison.value !== this.value;
}
/**
* Less than operator. Returns true if a < b.
* @brief Less than operator
* @return boolean - true if symbol `a` is less than `b`
*/
isLessThan(comparison) {
return this.value < comparison.value;
}
}
function symbol(sc, precision) {
return new Symbol(sc, precision);
}
// (() => {
// console.log(typeof new SymbolCode)
// console.log(typeof new SymbolCode("EOS"))
// console.log(symbol("A", 4).raw());
// console.log(symbol("AB", 4).raw());
// console.log(symbol("ABC", 4).raw());
// console.log(symbol("ABCD", 4).raw());
// console.log(symbol("ABCDE", 4).raw());
// console.log(symbol("ABCDEF", 4).raw());
// console.log(symbol("ABCDEFG", 4).raw());
// })();

@@ -263,2 +372,3 @@ // import { Decimal } from "decimal.js";

exports.Symbol = Symbol;
exports.SymbolCode = SymbolCode;
exports.asset_to_double = asset_to_double;

@@ -272,2 +382,3 @@ exports.block_timestamp_epoch = block_timestamp_epoch;

exports.stake2vote = stake2vote;
exports.symbol = symbol;
exports.symbol_code = symbol_code;

@@ -274,0 +385,0 @@ exports.vote2stake = vote2stake;

{
"name": "eos-common",
"version": "0.4.0",
"version": "0.4.1",
"description": "EOSIO Smart Contract common library used for Typescript",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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