fixed-width-parser
Advanced tools
Comparing version 2.5.1 to 3.0.0
# Change log | ||
## 3.0.0 | ||
- Add `date` parse `tryParsingRawValueBeforeFallback` option to attempt parsing the raw value as a | ||
Date before failing after failing to parse the trimmed value as a Date | ||
- Enhance `date` parse `falsyFallback == 'passthrough'` behavior to pass through trimmed value | ||
## 2.5.1 | ||
@@ -4,0 +10,0 @@ |
@@ -99,3 +99,15 @@ "use strict"; | ||
} | ||
var failValue = (0, handleFalsyFallback_1.handleFalsyFallback)(null, (_h = config.falsyFallback) !== null && _h !== void 0 ? _h : options.falsyFallback); | ||
if (config.tryParsingRawValueBeforeFallback) { | ||
var parsedRawDate = (0, date_fns_1.parse)(rawString, config.fixedWidthFormat, new Date()); | ||
if ((0, date_fns_1.isValid)(parsedRawDate)) { | ||
return (0, date_fns_1.format)(parsedRawDate, config.jsonFormat); | ||
} | ||
} | ||
var failValue = void 0; | ||
if (config.falsyFallback === 'passthrough') { | ||
failValue = trimmedString; | ||
} | ||
else { | ||
failValue = (0, handleFalsyFallback_1.handleFalsyFallback)(null, (_h = config.falsyFallback) !== null && _h !== void 0 ? _h : options.falsyFallback); | ||
} | ||
_this.logger.warn("Failed to parse to date value. Falling back to ".concat(failValue, ".")); | ||
@@ -102,0 +114,0 @@ return failValue; |
@@ -40,2 +40,3 @@ import { FalsyFallback } from './IParseOptions'; | ||
jsonFormat: string; | ||
tryParsingRawValueBeforeFallback: boolean; | ||
} | ||
@@ -42,0 +43,0 @@ export interface IBooleanParseConfig extends IBaseParseConfig { |
{ | ||
"name": "fixed-width-parser", | ||
"version": "2.5.1", | ||
"version": "3.0.0", | ||
"description": "A fixed width data parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -8,4 +8,3 @@ # fixed-width-parser | ||
`fixed-width-parser` is a node module for parsing data to and from fixed width string | ||
formats. | ||
`fixed-width-parser` is a node module for parsing data to and from fixed width string formats. | ||
@@ -129,5 +128,5 @@ ## Install | ||
When initializing a new instance of the `FixedWidthParser` class, you must provide | ||
an array of parse configs. These configs define how to convert between lines of | ||
text and json objects by providing a mapping between segments of text and object keys. | ||
When initializing a new instance of the `FixedWidthParser` class, you must provide an array of parse | ||
configs. These configs define how to convert between lines of text and json objects by providing a | ||
mapping between segments of text and object keys. | ||
@@ -161,5 +160,5 @@ All parse configs share the following properties: | ||
An explicit `type` property can be provided in each parse config to specify what | ||
data types to use for values parsed from strings. Several of these data types require | ||
additional properties to be provided to fully define how parse/unparse values. | ||
An explicit `type` property can be provided in each parse config to specify what data types to use | ||
for values parsed from strings. Several of these data types require additional properties to be | ||
provided to fully define how parse/unparse values. | ||
@@ -226,2 +225,5 @@ ```typescript | ||
jsonFormat: string; | ||
// attempt to parse raw value before failing if trimmed value is not parsable as a Date | ||
// default: false | ||
tryParsingRawValueBeforeFallback: boolean; | ||
} | ||
@@ -253,5 +255,5 @@ ``` | ||
When constructing a new `FixedWidthParser` instance the provided parse config will | ||
be validated. If any errors are detected an array of validation errors will be thrown | ||
to help you find and correct the invalid configs. | ||
When constructing a new `FixedWidthParser` instance the provided parse config will be validated. If | ||
any errors are detected an array of validation errors will be thrown to help you find and correct | ||
the invalid configs. | ||
@@ -315,4 +317,4 @@ ```typescript | ||
By default any logs from the parser will be handled by the built in `console` logger. | ||
You can optionally provide your own `ILogger` compatible logger to process logs. | ||
By default any logs from the parser will be handled by the built in `console` logger. You can | ||
optionally provide your own `ILogger` compatible logger to process logs. | ||
@@ -347,8 +349,6 @@ ```typescript | ||
A huge thanks to @SteveyPugs for his work on `fixy` which served as inspiration | ||
for `fixed-width-parser`! `fixed-width-parser` started out as a fork of `fixy` and | ||
evolved into its own library when I got carried away and implemented a new high-level | ||
API. | ||
A huge thanks to @SteveyPugs for his work on `fixy` which served as inspiration for | ||
`fixed-width-parser`! `fixed-width-parser` started out as a fork of `fixy` and evolved into its own | ||
library when I got carried away and implemented a new high-level API. | ||
Another huge thanks to @wk-davis for her help with concept discussions and ongoing | ||
development help! | ||
Another huge thanks to @wk-davis for her help with concept discussions and ongoing development help! |
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
41750
655