Skip to content

Commit

Permalink
Merge pull request #83 from DECENTfoundation/feature/exporting-stringify
Browse files Browse the repository at this point in the history
adding exported stringify
  • Loading branch information
Marian Vanderka authored Dec 18, 2019
2 parents b236546 + ac80093 commit beeae3f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gen/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export class Generator {
}
this.save();

this.apis.every((api) => {
this.apis.forEach((api) => {
const path = this.project.getDirectory(`${this.outApi}${api.packageSuffix}`);
if (path) {
rimraf(path.getPath(), (error) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dcorejs-sdk",
"version": "3.0.2",
"version": "3.0.3",
"homepage": "https://decent.ch/",
"description": "DcoreJS SDK.",
"main": "./dist/index.js",
Expand Down
18 changes: 11 additions & 7 deletions src/utils/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as BaseX from "base-x";
import { serialize } from "class-transformer";
import { classToPlain, serialize } from "class-transformer";
import * as Crypto from "crypto";
import { createHash } from "crypto";
import * as Long from "long";
Expand All @@ -22,26 +22,30 @@ export function info<T>(tag: string, logger: Logger): MonoTypeOperatorFunction<T
return tap({
complete: () => logger.info(`${tag}: #complete`),
error: (err) => logger.error(`${tag}: #error ${err.toString()}`),
next: (value) => logger.info(`${tag}: #next ${str(value)}`),
next: (value) => logger.info(`${tag}: #next ${Utils.stringify(value)}`),
});
}

export function debug<T>(tag: string, logger: Logger): MonoTypeOperatorFunction<T> {
return tap({
complete: () => logger.debug(`${tag}: #complete`),
error: (err) => logger.error(`${tag}: #error ${err.toString()}`),
next: (value) => logger.debug(`${tag}: #next ${str(value)}`),
next: (value) => logger.debug(`${tag}: #next ${Utils.stringify(value)}`),
});
}

function str(value: any): string {
return typeof value === "string" ? value : serialize(value);
}

export class Utils {

public static Base58 = BaseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");

public static stringify(value: any): string {
return typeof value === "string" ? value : serialize(value);
}

public static toPlain(value: any): object {
return classToPlain(value);
}

public static generateNonce(power: number = 250): Long {
return Long.fromString(Utils.generateEntropy(power).toString("hex"), true, 16);
}
Expand Down

0 comments on commit beeae3f

Please sign in to comment.