tiny-decoders
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -0,1 +1,11 @@ | ||
### Version 3.1.0 (2019-09-15) | ||
- Added: You can now set `repr.short = true` to get shorter error messages, | ||
containing only _where_ the error happened and the actual and expected types, | ||
but not showing any actual values. This is useful if you’re dealing with | ||
sensitive data, such as email addresses, passwords or social security numbers, | ||
you might not want that data to potentially appear in error logs. Another use | ||
case is if you simply prefer a shorter, oneline message. | ||
- Improved: Documentation on type inference in TypeScript. | ||
### Version 3.0.1 (2019-08-08) | ||
@@ -2,0 +12,0 @@ |
@@ -95,10 +95,13 @@ // TODO: TypeScript Version: 3.0 | ||
export function repr( | ||
value: unknown, | ||
options?: { | ||
key?: string | number; | ||
recurse?: boolean; | ||
maxArrayChildren?: number; | ||
maxObjectChildren?: number; | ||
} | ||
): string; | ||
export const repr: { | ||
( | ||
value: unknown, | ||
options?: { | ||
key?: string | number; | ||
recurse?: boolean; | ||
maxArrayChildren?: number; | ||
maxObjectChildren?: number; | ||
} | ||
): string; | ||
short: boolean; | ||
}; |
@@ -107,3 +107,3 @@ "use strict"; | ||
if (errors != null) { | ||
errors.push(keyErrorMessage(_index, arr, error.message)); | ||
errors.push(_message); | ||
} | ||
@@ -362,2 +362,4 @@ | ||
repr["short"] = false; | ||
function repr( // $FlowIgnore: Using `any` rather than `mixed` here to cut down on the bytes. | ||
@@ -379,7 +381,7 @@ value, _temp) { | ||
if (value == null || type === "number" || type === "boolean" || type === "symbol" || toStringType === "RegExp") { | ||
return truncate(String(value)); | ||
return repr["short"] ? toStringType.toLowerCase() : truncate(String(value)); | ||
} | ||
if (type === "string") { | ||
return printString(value); | ||
return repr["short"] ? type : printString(value); | ||
} | ||
@@ -476,5 +478,5 @@ | ||
"" : Object.prototype.hasOwnProperty.call(value, key) ? "" : key in value ? " (prototype)" : " (missing)"; | ||
return [prefix + "[" + at + "]", keyErrorPrefixRegex.test(message) ? "" : ": ", message.replace(keyErrorPrefixRegex, ""), "\nat " + at + missing + " in " + repr(value, { | ||
return [prefix + "[" + at + "]", keyErrorPrefixRegex.test(message) ? "" : ": ", message.replace(keyErrorPrefixRegex, ""), repr["short"] ? "" : "\nat " + at + missing + " in " + repr(value, { | ||
key: key | ||
})].join(""); | ||
} |
{ | ||
"name": "tiny-decoders", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
@@ -37,22 +37,22 @@ "author": "Simon Lydell", | ||
"devDependencies": { | ||
"@babel/cli": "7.5.5", | ||
"@babel/core": "7.5.5", | ||
"@babel/preset-env": "7.5.5", | ||
"@babel/cli": "7.6.0", | ||
"@babel/core": "7.6.0", | ||
"@babel/preset-env": "7.6.0", | ||
"@babel/preset-flow": "7.0.0", | ||
"babel-core": "7.0.0-bridge.0", | ||
"babel-eslint": "10.0.2", | ||
"babel-jest": "24.8.0", | ||
"decoders": "1.15.0", | ||
"babel-eslint": "10.0.3", | ||
"babel-jest": "24.9.0", | ||
"decoders": "1.16.1", | ||
"doctoc": "1.4.0", | ||
"dtslint": "0.9.1", | ||
"eslint": "6.1.0", | ||
"dtslint": "0.9.8", | ||
"eslint": "6.4.0", | ||
"eslint-config-lydell": "14.0.0", | ||
"eslint-plugin-flowtype": "3.13.0", | ||
"eslint-plugin-flowtype": "4.3.0", | ||
"eslint-plugin-flowtype-errors": "4.1.0", | ||
"eslint-plugin-import": "2.18.2", | ||
"eslint-plugin-jest": "22.15.0", | ||
"eslint-plugin-jest": "22.17.0", | ||
"eslint-plugin-prettier": "3.1.0", | ||
"eslint-plugin-simple-import-sort": "4.0.0", | ||
"flow-bin": "0.104.0", | ||
"jest": "24.8.0", | ||
"flow-bin": "0.107.0", | ||
"jest": "24.9.0", | ||
"npm-run-all": "4.1.5", | ||
@@ -59,0 +59,0 @@ "prettier": "1.18.2", |
@@ -43,2 +43,3 @@ # tiny-decoders [![Build Status][travis-badge]][travis-link] ![no dependencies][deps-tiny-decoders] [![minified size][min-tiny-decoders]][bundlephobia-tiny-decoders] | ||
- [`repr`](#repr) | ||
- [Short output (for sensitive data)](#short-output-for-sensitive-data) | ||
- [Comparison with nvie/decoders](#comparison-with-nviedecoders) | ||
@@ -206,3 +207,3 @@ - [Error messages](#error-messages) | ||
the [Flow type annotations example][example-type-annotations] for more | ||
information. | ||
information, tips and caveats. | ||
@@ -958,2 +959,37 @@ ## API | ||
#### Short output (for sensitive data) | ||
By default, the tiny-decoder’s error messages try to be helpful by showing you | ||
the actual values that failed decoding to make it easier to understand what | ||
happened. However, if you’re dealing with sensitive data, such as email | ||
addresses, passwords or social security numbers, you might not want that data to | ||
potentially appear in error logs. Another use case is if you simply prefer a | ||
shorter, oneline message. | ||
By setting `repr.short = true` you will get shorter error messages, containing | ||
only _where_ the error happened and the actual and expected types, but not | ||
showing any actual values. | ||
Standard: | ||
``` | ||
object["details"]["ssn"]: Expected a string, but got: 123456789 | ||
at "ssn" in {"ssn": 123456789, "email": "john.doe@…mple.com"} | ||
at "details" in {"details": Object(2), "name": "John Doe"} | ||
``` | ||
With `repr.short = true`: | ||
``` | ||
object["details"]["ssn"]: Expected a string, but got: number | ||
``` | ||
All decoders use `repr` internally when making their error messages, so setting | ||
`repr.short` affect them too. This is admittedly not the most beautiful API, but | ||
it is tiny. | ||
If you need _both_ standard _and_ short output in the same application – | ||
remember that `repr.short = true` globally affects everything. You’ll need to | ||
flip `repr.short` back and forth as needed. | ||
## Comparison with nvie/decoders | ||
@@ -960,0 +996,0 @@ |
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
91903
832
1183