appolo-utils
Advanced tools
Comparing version 0.0.54 to 0.0.55
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const index_1 = require("../index"); | ||
class Errors { | ||
@@ -13,4 +14,13 @@ static stack() { | ||
} | ||
static errorToString(err) { | ||
let output = ""; | ||
if (!err) { | ||
return output; | ||
} | ||
return (err instanceof Error) | ||
? err.stack || err.toString() | ||
: index_1.Objects.tryStringifyJSON(err); | ||
} | ||
} | ||
exports.Errors = Errors; | ||
//# sourceMappingURL=errors.js.map |
import CallSite = NodeJS.CallSite; | ||
import {Objects} from "../index"; | ||
@@ -17,3 +18,16 @@ export class Errors { | ||
public static errorToString(err: Error): string { | ||
let output = ""; | ||
if (!err) { | ||
return output | ||
} | ||
return (err instanceof Error) | ||
? err.stack || err.toString() | ||
: Objects.tryStringifyJSON(err) | ||
} | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const arrays_1 = require("./arrays"); | ||
const index_1 = require("../index"); | ||
class Objects { | ||
@@ -75,10 +76,9 @@ static isPlain(obj) { | ||
static tryParseJSON(jsonString) { | ||
try { | ||
let o = JSON.parse(jsonString); | ||
return o; | ||
} | ||
catch (e) { | ||
} | ||
return null; | ||
let [err, output] = index_1.Functions.to(() => JSON.parse(jsonString)); | ||
return err ? null : output; | ||
} | ||
static tryStringifyJSON(json) { | ||
let [err, str] = index_1.Functions.to(() => JSON.stringify(json)); | ||
return err ? "" : str; | ||
} | ||
static pick(obj, ...pick) { | ||
@@ -85,0 +85,0 @@ let out = {}; |
import {Arrays} from "./arrays"; | ||
import {Functions} from "../index"; | ||
@@ -103,11 +104,13 @@ export class Objects { | ||
public static tryParseJSON(jsonString: string): any { | ||
try { | ||
let o = JSON.parse(jsonString); | ||
let [err, output] = Functions.to(() => JSON.parse(jsonString)); | ||
return o; | ||
} catch (e) { | ||
} | ||
return err ? null : output; | ||
} | ||
return null; | ||
public static tryStringifyJSON(json: any): string { | ||
let [err, str] = Functions.to(() => JSON.stringify(json)) | ||
return err ? "" : str; | ||
} | ||
@@ -120,3 +123,3 @@ | ||
let key = pick[i]; | ||
if(key in obj){ | ||
if (key in obj) { | ||
out[key] = obj[key]; | ||
@@ -123,0 +126,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const index_1 = require("../index"); | ||
class Strings { | ||
@@ -29,8 +30,4 @@ static stringifyObjectValues(obj) { | ||
static tryDecodeURIComponent(str) { | ||
try { | ||
return decodeURIComponent(str || ""); | ||
} | ||
catch (e) { | ||
return str || ""; | ||
} | ||
let [err, output] = index_1.Functions.to(() => decodeURIComponent(str || "")); | ||
return err ? str || "" : output; | ||
} | ||
@@ -37,0 +34,0 @@ } |
@@ -0,1 +1,3 @@ | ||
import {Functions} from "../index"; | ||
export class Strings { | ||
@@ -34,8 +36,7 @@ public static stringifyObjectValues(obj: { [index: string]: string | boolean | number }): string { | ||
public static tryDecodeURIComponent(str): string { | ||
try { | ||
return decodeURIComponent(str || ""); | ||
} catch (e) { | ||
return str || "" | ||
} | ||
let [err, output] = Functions.to(() => decodeURIComponent(str || "")); | ||
return err ? str || "" : output; | ||
} | ||
} |
@@ -17,3 +17,3 @@ { | ||
"main": "./index.js", | ||
"version": "0.0.54", | ||
"version": "0.0.55", | ||
"license": "MIT", | ||
@@ -20,0 +20,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118457
2117