@fgv/ts-utils 2.0.2-alpha.0 → 2.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ts-utils.d.ts +1509 -1924
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts +1 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -9
- package/lib/index.js.map +1 -1
- package/lib/packlets/base/logger.js.map +1 -1
- package/lib/packlets/base/normalize.js.map +1 -1
- package/lib/packlets/base/result.d.ts +20 -6
- package/lib/packlets/base/result.d.ts.map +1 -1
- package/lib/packlets/base/result.js +4 -6
- package/lib/packlets/base/result.js.map +1 -1
- package/lib/packlets/base/utils.d.ts +7 -7
- package/lib/packlets/base/utils.d.ts.map +1 -1
- package/lib/packlets/base/utils.js +4 -4
- package/lib/packlets/base/utils.js.map +1 -1
- package/lib/packlets/conversion/converter.js.map +1 -1
- package/lib/packlets/conversion/converters.d.ts +5 -29
- package/lib/packlets/conversion/converters.d.ts.map +1 -1
- package/lib/packlets/conversion/converters.js +1 -47
- package/lib/packlets/conversion/converters.js.map +1 -1
- package/lib/packlets/conversion/objectConverter.js.map +1 -1
- package/lib/packlets/conversion/stringConverter.js.map +1 -1
- package/lib/packlets/validation/array.js.map +1 -1
- package/lib/packlets/validation/boolean.js.map +1 -1
- package/lib/packlets/validation/field.js.map +1 -1
- package/lib/packlets/validation/genericValidator.js.map +1 -1
- package/lib/packlets/validation/number.js.map +1 -1
- package/lib/packlets/validation/object.js.map +1 -1
- package/lib/packlets/validation/string.js.map +1 -1
- package/lib/packlets/validation/typeGuard.js.map +1 -1
- package/lib/packlets/validation/validators.js.map +1 -1
- package/package.json +29 -30
- package/lib/packlets/csv/csvHelpers.d.ts +0 -17
- package/lib/packlets/csv/csvHelpers.d.ts.map +0 -1
- package/lib/packlets/csv/csvHelpers.js +0 -69
- package/lib/packlets/csv/csvHelpers.js.map +0 -1
- package/lib/packlets/csv/index.d.ts +0 -2
- package/lib/packlets/csv/index.d.ts.map +0 -1
- package/lib/packlets/csv/index.js +0 -39
- package/lib/packlets/csv/index.js.map +0 -1
- package/lib/packlets/experimental/extendedArray.d.ts +0 -56
- package/lib/packlets/experimental/extendedArray.d.ts.map +0 -1
- package/lib/packlets/experimental/extendedArray.js +0 -106
- package/lib/packlets/experimental/extendedArray.js.map +0 -1
- package/lib/packlets/experimental/formatter.d.ts +0 -66
- package/lib/packlets/experimental/formatter.d.ts.map +0 -1
- package/lib/packlets/experimental/formatter.js +0 -75
- package/lib/packlets/experimental/formatter.js.map +0 -1
- package/lib/packlets/experimental/index.d.ts +0 -4
- package/lib/packlets/experimental/index.d.ts.map +0 -1
- package/lib/packlets/experimental/index.js +0 -41
- package/lib/packlets/experimental/index.js.map +0 -1
- package/lib/packlets/experimental/rangeOf.d.ts +0 -122
- package/lib/packlets/experimental/rangeOf.d.ts.map +0 -1
- package/lib/packlets/experimental/rangeOf.js +0 -185
- package/lib/packlets/experimental/rangeOf.js.map +0 -1
- package/lib/packlets/hash/hash.d.ts +0 -51
- package/lib/packlets/hash/hash.d.ts.map +0 -1
- package/lib/packlets/hash/hash.js +0 -166
- package/lib/packlets/hash/hash.js.map +0 -1
- package/lib/packlets/hash/index.d.ts +0 -2
- package/lib/packlets/hash/index.d.ts.map +0 -1
- package/lib/packlets/hash/index.js +0 -39
- package/lib/packlets/hash/index.js.map +0 -1
- package/lib/packlets/record-jar/index.d.ts +0 -2
- package/lib/packlets/record-jar/index.d.ts.map +0 -1
- package/lib/packlets/record-jar/index.js +0 -39
- package/lib/packlets/record-jar/index.js.map +0 -1
- package/lib/packlets/record-jar/recordJarHelpers.d.ts +0 -37
- package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +0 -1
- package/lib/packlets/record-jar/recordJarHelpers.js +0 -263
- package/lib/packlets/record-jar/recordJarHelpers.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources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KAAK,CAAC;iBAC/B;qBAAM,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE;oBAC7B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;iBAC7B;aACF;SACF;QAED,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,cAAe,CAAC,GAAG,CAAC,CAAY,CAAC,CAAC,CAAC;YACzF,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,sCAAsC,CAAC,CAAC,CAAC;SACrF;QACD,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,WAAI,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AAjID,0CAiIC","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { Validator, ValidatorOptions } from './validator';\nimport { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';\n\nimport { FieldValidator } from './field';\n\n/**\n * Per-property {@link Validation.Validator | validators} for each of the properties in `<T>`.\n * @public\n */\nexport type FieldValidators<T, TC = unknown> = { [key in keyof T]: Validator<T[key], TC> };\n\n/**\n * Options for an {@link Validation.Classes.ObjectValidator | ObjectValidator}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface ObjectValidatorOptions<T, TC> extends ValidatorOptions<TC> {\n /**\n * If present, lists optional fields. Missing non-optional fields cause an error.\n */\n optionalFields?: (keyof T)[];\n /**\n * If true, unrecognized fields yield an error. If false or undefined (default),\n * unrecognized fields are ignored.\n */\n strict?: boolean;\n}\n\n/**\n * Options for the {@link Validation.Classes.ObjectValidator | ObjectValidator} constructor.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface ObjectValidatorConstructorParams<T, TC> extends ValidatorBaseConstructorParams<T, TC> {\n /**\n * A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a\n * {@link Validation.Validator | Validator} for each of the expected properties\n * of a result object.\n */\n fields: FieldValidators<T>;\n /**\n * Optional additional {@link Validation.Classes.ObjectValidatorOptions | ValidatorOptions} to\n * configure validation.\n */\n options?: ObjectValidatorOptions<T, TC>;\n}\n\n/**\n * In-place {@link Validation.Validator | Validator} for an object of type `<T>`.\n * @remarks\n * By default, succeeds if all of the required fields exist and are validate, and fails if\n * any required fields do not exist or are invalid. See {@link Validation.Classes.ObjectValidatorOptions}\n * for other validation options.\n * @public\n */\nexport class ObjectValidator<T, TC = unknown> extends ValidatorBase<T, TC> {\n /**\n * A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a\n * {@link Validation.Validator | Validator} for each of the expected properties\n */\n public readonly fields: FieldValidators<T>;\n /**\n * {@link Validation.Classes.ObjectValidatorOptions | Options} which apply to this\n * validator.\n */\n public readonly options: ObjectValidatorOptions<T, TC>;\n /**\n * @internal\n */\n protected readonly _innerValidators: FieldValidators<T>;\n /**\n * @internal\n */\n protected readonly _allowedFields?: Set<keyof T>;\n\n /**\n * Constructs a new {@link Validation.Classes.ObjectValidator | ObjectValidator<T>}.\n * @param fields - A {@link Validation.Classes.FieldValidators | FieldValidators<T>} containing\n * a {@link Validation.Validator | Validator} for each field.\n * @param options - An optional {@link Validation.Classes.ObjectValidatorOptions} to configure\n * validation.\n */\n public constructor(params: ObjectValidatorConstructorParams<T, TC>) {\n super(params);\n\n this.fields = params.fields;\n this.options = params.options ?? {};\n this._innerValidators = ObjectValidator._resolveValidators(this.fields, this.options);\n this._allowedFields =\n this.options.strict === true ? new Set(Object.keys(this.fields) as (keyof T)[]) : undefined;\n }\n\n /**\n * Creates the actual {@link Validation.Classes.FieldValidators | FieldValidators<T>} to be\n * used by this converter by applying any options or traits defined in the options\n * to the field converters passed to the constructor.\n * @param fields - The base {@link Validation.Classes.FieldValidators | FieldValidators<T>} passed\n * in to the constructor.\n * @param options - The {@link Validation.Classes.ObjectValidatorOptions | object validator options}\n * passed in to the constructor.\n * @returns A new {@link Validation.Classes.FieldValidators | FieldValidators} with the fully-configured\n * individual {@link Validation.Validator | field validators} to be applied.\n * @internal\n */\n protected static _resolveValidators<T, TC>(\n fields: FieldValidators<T, TC>,\n options?: ObjectValidatorOptions<T, TC>\n ): FieldValidators<T, TC> {\n const resolved: Partial<FieldValidators<T, TC>> = {};\n for (const key in fields) {\n if (fields[key]) {\n /* c8 ignore next */\n const optional = fields[key].isOptional || options?.optionalFields?.includes(key);\n resolved[key] = new FieldValidator(key, fields[key], { optional });\n }\n }\n return resolved as FieldValidators<T, TC>;\n }\n\n /**\n * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with\n * new optional properties as specified by a supplied\n * {@link Validation.Classes.ObjectValidatorOptions | ObjectValidatorOptions<T>}.\n * @param options - The {@link Validation.Classes.ObjectValidatorOptions | options} to be applied to the new\n * {@link Validation.Classes.ObjectValidator | validator}.\n * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional\n * source properties.\n */\n public partial(options?: ObjectValidatorOptions<T, TC>): ObjectValidator<Partial<T>, TC> {\n /* c8 ignore next */\n options = options ?? {};\n return new ObjectValidator<Partial<T>, TC>({\n fields: this.fields as FieldValidators<Partial<T>, TC>,\n options: {\n ...this.options,\n ...options\n },\n traits: this.traits\n });\n }\n\n /**\n * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with\n * new optional properties as specified by a supplied array of `keyof T`.\n * @param addOptionalProperties - The keys to be made optional.\n * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional\n * source properties.\n */\n public addPartial(addOptionalFields: (keyof T)[]): ObjectValidator<Partial<T>, TC> {\n return this.partial({\n optionalFields: [...(this.options.optionalFields ?? []), ...addOptionalFields]\n });\n }\n\n /**\n * {@inheritdoc Validation.ValidatorBase._validate}\n * @internal\n */\n protected _validate(from: unknown, context?: TC): boolean | Failure<T> {\n if (typeof from !== 'object' || from === null || Array.isArray(from)) {\n return fail('source is not an object');\n }\n\n // eslint bug thinks key is used before defined\n // eslint-disable-next-line no-use-before-define\n const converted = {} as { [key in keyof T]: T[key] };\n const errors: string[] = [];\n for (const key in this._innerValidators) {\n if (this._innerValidators[key]) {\n const result = this._innerValidators[key].validate(from, context);\n if (result.success && result.value !== undefined) {\n converted[key] = result.value;\n } else if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n }\n\n if (this._allowedFields) {\n const invalid = Object.keys(from).filter((k) => !this._allowedFields!.has(k as keyof T));\n invalid.forEach((key) => errors.push(`${key}: unexpected field in source object.`));\n }\n return errors.length === 0 ? true : fail(errors.join('\\n'));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":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,KAAK,SAAS,EAAE,CAAC;oBACjD,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;gBAChC,CAAC;qBAAM,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;oBAC9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,cAAe,CAAC,GAAG,CAAC,CAAY,CAAC,CAAC,CAAC;YACzF,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,sCAAsC,CAAC,CAAC,CAAC;QACtF,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,WAAI,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AAjID,0CAiIC","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { Validator, ValidatorOptions } from './validator';\nimport { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';\n\nimport { FieldValidator } from './field';\n\n/**\n * Per-property {@link Validation.Validator | validators} for each of the properties in `<T>`.\n * @public\n */\nexport type FieldValidators<T, TC = unknown> = { [key in keyof T]: Validator<T[key], TC> };\n\n/**\n * Options for an {@link Validation.Classes.ObjectValidator | ObjectValidator}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface ObjectValidatorOptions<T, TC> extends ValidatorOptions<TC> {\n /**\n * If present, lists optional fields. Missing non-optional fields cause an error.\n */\n optionalFields?: (keyof T)[];\n /**\n * If true, unrecognized fields yield an error. If false or undefined (default),\n * unrecognized fields are ignored.\n */\n strict?: boolean;\n}\n\n/**\n * Options for the {@link Validation.Classes.ObjectValidator | ObjectValidator} constructor.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface ObjectValidatorConstructorParams<T, TC> extends ValidatorBaseConstructorParams<T, TC> {\n /**\n * A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a\n * {@link Validation.Validator | Validator} for each of the expected properties\n * of a result object.\n */\n fields: FieldValidators<T>;\n /**\n * Optional additional {@link Validation.Classes.ObjectValidatorOptions | ValidatorOptions} to\n * configure validation.\n */\n options?: ObjectValidatorOptions<T, TC>;\n}\n\n/**\n * In-place {@link Validation.Validator | Validator} for an object of type `<T>`.\n * @remarks\n * By default, succeeds if all of the required fields exist and are validate, and fails if\n * any required fields do not exist or are invalid. See {@link Validation.Classes.ObjectValidatorOptions}\n * for other validation options.\n * @public\n */\nexport class ObjectValidator<T, TC = unknown> extends ValidatorBase<T, TC> {\n /**\n * A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a\n * {@link Validation.Validator | Validator} for each of the expected properties\n */\n public readonly fields: FieldValidators<T>;\n /**\n * {@link Validation.Classes.ObjectValidatorOptions | Options} which apply to this\n * validator.\n */\n public readonly options: ObjectValidatorOptions<T, TC>;\n /**\n * @internal\n */\n protected readonly _innerValidators: FieldValidators<T>;\n /**\n * @internal\n */\n protected readonly _allowedFields?: Set<keyof T>;\n\n /**\n * Constructs a new {@link Validation.Classes.ObjectValidator | ObjectValidator<T>}.\n * @param fields - A {@link Validation.Classes.FieldValidators | FieldValidators<T>} containing\n * a {@link Validation.Validator | Validator} for each field.\n * @param options - An optional {@link Validation.Classes.ObjectValidatorOptions} to configure\n * validation.\n */\n public constructor(params: ObjectValidatorConstructorParams<T, TC>) {\n super(params);\n\n this.fields = params.fields;\n this.options = params.options ?? {};\n this._innerValidators = ObjectValidator._resolveValidators(this.fields, this.options);\n this._allowedFields =\n this.options.strict === true ? new Set(Object.keys(this.fields) as (keyof T)[]) : undefined;\n }\n\n /**\n * Creates the actual {@link Validation.Classes.FieldValidators | FieldValidators<T>} to be\n * used by this converter by applying any options or traits defined in the options\n * to the field converters passed to the constructor.\n * @param fields - The base {@link Validation.Classes.FieldValidators | FieldValidators<T>} passed\n * in to the constructor.\n * @param options - The {@link Validation.Classes.ObjectValidatorOptions | object validator options}\n * passed in to the constructor.\n * @returns A new {@link Validation.Classes.FieldValidators | FieldValidators} with the fully-configured\n * individual {@link Validation.Validator | field validators} to be applied.\n * @internal\n */\n protected static _resolveValidators<T, TC>(\n fields: FieldValidators<T, TC>,\n options?: ObjectValidatorOptions<T, TC>\n ): FieldValidators<T, TC> {\n const resolved: Partial<FieldValidators<T, TC>> = {};\n for (const key in fields) {\n if (fields[key]) {\n /* c8 ignore next */\n const optional = fields[key].isOptional || options?.optionalFields?.includes(key);\n resolved[key] = new FieldValidator(key, fields[key], { optional });\n }\n }\n return resolved as FieldValidators<T, TC>;\n }\n\n /**\n * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with\n * new optional properties as specified by a supplied\n * {@link Validation.Classes.ObjectValidatorOptions | ObjectValidatorOptions<T>}.\n * @param options - The {@link Validation.Classes.ObjectValidatorOptions | options} to be applied to the new\n * {@link Validation.Classes.ObjectValidator | validator}.\n * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional\n * source properties.\n */\n public partial(options?: ObjectValidatorOptions<T, TC>): ObjectValidator<Partial<T>, TC> {\n /* c8 ignore next */\n options = options ?? {};\n return new ObjectValidator<Partial<T>, TC>({\n fields: this.fields as FieldValidators<Partial<T>, TC>,\n options: {\n ...this.options,\n ...options\n },\n traits: this.traits\n });\n }\n\n /**\n * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with\n * new optional properties as specified by a supplied array of `keyof T`.\n * @param addOptionalProperties - The keys to be made optional.\n * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional\n * source properties.\n */\n public addPartial(addOptionalFields: (keyof T)[]): ObjectValidator<Partial<T>, TC> {\n return this.partial({\n optionalFields: [...(this.options.optionalFields ?? []), ...addOptionalFields]\n });\n }\n\n /**\n * {@inheritdoc Validation.ValidatorBase._validate}\n * @internal\n */\n protected _validate(from: unknown, context?: TC): boolean | Failure<T> {\n if (typeof from !== 'object' || from === null || Array.isArray(from)) {\n return fail('source is not an object');\n }\n\n // eslint bug thinks key is used before defined\n // eslint-disable-next-line no-use-before-define\n const converted = {} as { [key in keyof T]: T[key] };\n const errors: string[] = [];\n for (const key in this._innerValidators) {\n if (this._innerValidators[key]) {\n const result = this._innerValidators[key].validate(from, context);\n if (result.success && result.value !== undefined) {\n converted[key] = result.value;\n } else if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n }\n\n if (this._allowedFields) {\n const invalid = Object.keys(from).filter((k) => !this._allowedFields!.has(k as keyof T));\n invalid.forEach((key) => errors.push(`${key}: unexpected field in source object.`));\n }\n return errors.length === 0 ? true : fail(errors.join('\\n'));\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src/packlets/validation/string.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,yDAAyF;AAWzF;;;GAGG;AACH,MAAa,eAAyD,SAAQ,mCAAuB;IACnG;;;;OAIG;IACH,YAAmB,MAAgD;QACjE,KAAK,iBACH,SAAS,EAAE,eAAe,CAAC,cAAc,IACtC,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EACjB,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,cAAc,CAAmB,IAAa;QAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src/packlets/validation/string.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,yDAAyF;AAWzF;;;GAGG;AACH,MAAa,eAAyD,SAAQ,mCAAuB;IACnG;;;;OAIG;IACH,YAAmB,MAAgD;QACjE,KAAK,iBACH,SAAS,EAAE,eAAe,CAAC,cAAc,IACtC,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EACjB,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,cAAc,CAAmB,IAAa;QAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAA,WAAI,EAAI,IAAI,IAAI,iBAAiB,CAAC,CAAC;IAC5C,CAAC;CACF;AAzBD,0CAyBC","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.StringValidator | StringValidator}.\n * @public\n */\nexport type StringValidatorConstructorParams<\n T extends string = string,\n TC = unknown\n> = GenericValidatorConstructorParams<T, TC>;\n\n/**\n * An in-place {@link Validation.Validator | Validator} for `string` values.\n * @public\n */\nexport class StringValidator<T extends string = string, TC = unknown> extends GenericValidator<T, TC> {\n /**\n * Constructs a new {@link Validation.Classes.StringValidator | StringValidator}.\n * @param params - Optional {@link Validation.Classes.StringValidatorConstructorParams | init params}\n * for the new {@link Validation.Classes.StringValidator | StringValidator}.\n */\n public constructor(params?: StringValidatorConstructorParams<T, TC>) {\n super({\n validator: StringValidator.validateString,\n ...(params ?? {})\n });\n }\n\n /**\n * Static method which validates that a supplied `unknown` value is a `string`.\n * @param from - The `unknown` value to be tested.\n * @returns Returns `true` if `from` is a `string`, or {@link Failure} with an error\n * message if not.\n */\n public static validateString<T extends string>(from: unknown): boolean | Failure<T> {\n if (typeof from === 'string') {\n return true;\n }\n return fail<T>(`\"${from}\": not a string`);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeGuard.js","sourceRoot":"","sources":["../../../src/packlets/validation/typeGuard.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,mDAAgF;AAgBhF;;;;GAIG;AACH,MAAa,kBAAoC,SAAQ,6BAAoB;IAU3E;;;;OAIG;IACH,YAAmB,MAAkD;;QACnE,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;;OAQG;IACO,SAAS,CAAC,IAAa,EAAE,OAAY;QAC7C,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"typeGuard.js","sourceRoot":"","sources":["../../../src/packlets/validation/typeGuard.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,mDAAgF;AAgBhF;;;;GAIG;AACH,MAAa,kBAAoC,SAAQ,6BAAoB;IAU3E;;;;OAIG;IACH,YAAmB,MAAkD;;QACnE,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;;OAQG;IACO,SAAS,CAAC,IAAa,EAAE,OAAY;QAC7C,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAA,WAAI,EAAC,WAAW,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvE,CAAC;CACF;AArCD,gDAqCC","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';\n\nimport { TypeGuardWithContext } from './common';\nimport { ValidatorOptions } from './validator';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.TypeGuardValidator}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface TypeGuardValidatorConstructorParams<T, TC = unknown>\n extends ValidatorBaseConstructorParams<T, TC> {\n guard: TypeGuardWithContext<T, TC>;\n description: string;\n}\n\n/**\n * An in-place {@link Validation.Validator | Validator} that can be instantiated using a type guard\n * function.\n * @public\n */\nexport class TypeGuardValidator<T, TC = unknown> extends ValidatorBase<T, TC> {\n /**\n * {@link Validation.ValidatorOptions | Options} which apply to this\n * validator.\n */\n public readonly options: ValidatorOptions<TC>;\n public readonly description: string;\n\n protected readonly _guard: TypeGuardWithContext<T, TC>;\n\n /**\n * Constructs a new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.\n * @param params - Optional {@link Validation.Classes.TypeGuardValidatorConstructorParams | init params} for the\n * new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.\n */\n public constructor(params: TypeGuardValidatorConstructorParams<T, TC>) {\n super(params);\n this.description = params.description;\n this._guard = params.guard;\n this.options = params.options ?? {};\n }\n\n /**\n * Static method which validates that a supplied `unknown` value matches the supplied\n * type guard, returning a `Failure<T>` containing more information about a failure.\n * @param from - Value to be converted.\n * @param context - Optional validation context.\n * @returns `true` if `from` is valid, {@link Failure | Failure<T>}\n * with an error message if `from` is invalid.\n * @internal\n */\n protected _validate(from: unknown, context?: TC): boolean | Failure<T> {\n if (this._guard(from, context)) {\n return true;\n }\n return fail(`invalid ${this.description} (${JSON.stringify(from)})`);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/packlets/validation/validators.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,mCAA0E;AAC1E,qCAA8F;AAC9F,2CAAsF;AAEtF,uCAA6C;AAE7C,yDAAsD;AACtD,qCAA2C;AAC3C,qCAA2C;AAG3C;;;GAGG;AACU,QAAA,MAAM,GAAsB,IAAI,wBAAe,EAAE,CAAC;AAE/D;;;GAGG;AACU,QAAA,MAAM,GAAsB,IAAI,wBAAe,EAAE,CAAC;AAE/D;;;GAGG;AACU,QAAA,OAAO,GAAuB,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,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAVD,0BAUC;AAED;;;;;;;;GAQG;AACH,SAAgB,GAAG,CACjB,WAAmB,EACnB,KAAkC,EAClC,MAAkF;IAElF,OAAO,IAAI,8BAAkB,iBAAG,WAAW,EAAE,KAAK,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAG,CAAC;AAC3E,CAAC;AAND,kBAMC","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { ArrayValidator, ArrayValidatorConstructorParams } from './array';\nimport { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';\nimport { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';\n\nimport { BooleanValidator } from './boolean';\nimport { TypeGuardWithContext } from './common';\nimport { GenericValidator } from './genericValidator';\nimport { NumberValidator } from './number';\nimport { StringValidator } from './string';\nimport { Validator } from './validator';\n\n/**\n * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.\n * @public\n */\nexport const string: Validator<string> = new StringValidator();\n\n/**\n * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.\n * @public\n */\nexport const number: Validator<number> = new NumberValidator();\n\n/**\n * A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.\n * @public\n */\nexport const boolean: Validator<boolean> = new BooleanValidator();\n\n/**\n * Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates\n * an object in place.\n * @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}\n * describing the validations to be applied.\n * @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}\n * to refine the behavior of the resulting {@link Validation.Validator | validator}.\n * @returns A new {@link Validation.Validator | Validator} which validates the desired\n * object in place.\n * @public\n */\nexport function object<T, TC = unknown>(\n fields: FieldValidators<T, TC>,\n params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>\n): ObjectValidator<T, TC> {\n return new ObjectValidator({ fields, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.ArrayValidator | ArrayValidator} which\n * validates an array in place.\n * @param validateElement - A {@link Validation.Validator | validator} which validates each element.\n * @returns A new {@link Validation.Classes.ArrayValidator | ArrayValidator } which validates the desired\n * array in place.\n * @public\n */\nexport function arrayOf<T, TC>(\n validateElement: Validator<T, TC>,\n params?: Omit<ArrayValidatorConstructorParams<T, TC>, 'validateElement'>\n): ArrayValidator<T, TC> {\n return new ArrayValidator({ validateElement, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates an enumerated\n * value in place.\n * @public\n */\nexport function enumeratedValue<T extends string>(values: T[]): Validator<T, T[]> {\n return new GenericValidator({\n validator: (from: unknown, context?: T[]): boolean | Failure<T> => {\n if (typeof from === 'string') {\n const v = context ?? values;\n const index = v.indexOf(from as T);\n return index >= 0 ? true : fail(`Invalid enumerated value \"${from}\" - expected: (${v.join(', ')})`);\n }\n return fail(`Not a string: \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates a literal value.\n * @param value - the literal value to be validated\n * @public\n */\nexport function literal<T extends string | number | boolean | symbol | null | undefined>(\n value: T\n): Validator<T> {\n return new GenericValidator({\n validator: (from: unknown): boolean | Failure<T> => {\n return from === value\n ? true\n : fail(`Expected literal ${String(value)}, found \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which\n * validates a value or object in place.\n * @param description - a description of the thing to be validated for use in error messages\n * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.\n * @returns A new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator } which validates\n * the values using the supplied type guard.\n * @public\n */\nexport function isA<T, TC>(\n description: string,\n guard: TypeGuardWithContext<T, TC>,\n params?: Omit<TypeGuardValidatorConstructorParams<T, TC>, 'description' | 'guard'>\n): TypeGuardValidator<T, TC> {\n return new TypeGuardValidator({ description, guard, ...(params ?? {}) });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1-alpha.0",
|
|
4
4
|
"description": "Assorted Typescript Utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-utils.d.ts",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"lint": "eslint src --ext .ts",
|
|
17
17
|
"fixlint": "eslint src --ext .ts --fix"
|
|
18
18
|
},
|
|
19
|
+
"sideEffects": false,
|
|
19
20
|
"keywords": [
|
|
20
21
|
"typescript",
|
|
21
22
|
"json"
|
|
@@ -27,40 +28,38 @@
|
|
|
27
28
|
},
|
|
28
29
|
"homepage": "https://github.com/ErikFortune/fgv#readme",
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@jest/expect-utils": "^29.
|
|
31
|
-
"@microsoft/api-documenter": "^7.
|
|
32
|
-
"@microsoft/api-extractor": "^7.
|
|
33
|
-
"@types/jest": "^29.5.
|
|
34
|
-
"@types/luxon": "^3.
|
|
35
|
-
"@types/mustache": "^4.2.
|
|
36
|
-
"@types/node": "^20.
|
|
37
|
-
"@
|
|
38
|
-
"@typescript-eslint/
|
|
39
|
-
"
|
|
40
|
-
"eslint": "^8.42.0",
|
|
31
|
+
"@jest/expect-utils": "^29.7.0",
|
|
32
|
+
"@microsoft/api-documenter": "^7.23.17",
|
|
33
|
+
"@microsoft/api-extractor": "^7.39.1",
|
|
34
|
+
"@types/jest": "^29.5.11",
|
|
35
|
+
"@types/luxon": "^3.4.1",
|
|
36
|
+
"@types/mustache": "^4.2.5",
|
|
37
|
+
"@types/node": "^20.11.5",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
39
|
+
"@typescript-eslint/parser": "^6.19.0",
|
|
40
|
+
"eslint": "^8.56.0",
|
|
41
41
|
"eslint-config-standard": "^17.1.0",
|
|
42
|
-
"eslint-plugin-import": "^2.
|
|
42
|
+
"eslint-plugin-import": "^2.29.1",
|
|
43
43
|
"eslint-plugin-node": "^11.1.0",
|
|
44
44
|
"eslint-plugin-promise": "^6.1.1",
|
|
45
|
-
"jest": "^29.
|
|
46
|
-
"jest-extended": "^4.0.
|
|
47
|
-
"jest-matcher-utils": "^29.
|
|
48
|
-
"rimraf": "^5.0.
|
|
49
|
-
"ts-jest": "^29.1.
|
|
50
|
-
"ts-node": "^10.9.
|
|
51
|
-
"typescript": "^5.
|
|
52
|
-
"eslint-plugin-n": "^16.
|
|
53
|
-
"jest-snapshot": "~29.
|
|
54
|
-
"@rushstack/heft": "~0.
|
|
55
|
-
"@rushstack/heft-node-rig": "~2.
|
|
56
|
-
"@rushstack/eslint-config": "~3.
|
|
57
|
-
"@types/heft-jest": "1.0.
|
|
58
|
-
"@rushstack/heft-jest-plugin": "~0.
|
|
45
|
+
"jest": "^29.7.0",
|
|
46
|
+
"jest-extended": "^4.0.2",
|
|
47
|
+
"jest-matcher-utils": "^29.7.0",
|
|
48
|
+
"rimraf": "^5.0.5",
|
|
49
|
+
"ts-jest": "^29.1.1",
|
|
50
|
+
"ts-node": "^10.9.2",
|
|
51
|
+
"typescript": "^5.3.3",
|
|
52
|
+
"eslint-plugin-n": "^16.6.2",
|
|
53
|
+
"jest-snapshot": "~29.7.0",
|
|
54
|
+
"@rushstack/heft": "~0.64.0",
|
|
55
|
+
"@rushstack/heft-node-rig": "~2.4.0",
|
|
56
|
+
"@rushstack/eslint-config": "~3.6.0",
|
|
57
|
+
"@types/heft-jest": "1.0.6",
|
|
58
|
+
"@rushstack/heft-jest-plugin": "~0.11.0",
|
|
59
59
|
"eslint-plugin-tsdoc": "~0.2.17"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"luxon": "^3.
|
|
63
|
-
"mustache": "^4.2.0"
|
|
64
|
-
"papaparse": "^5.4.1"
|
|
62
|
+
"luxon": "^3.4.4",
|
|
63
|
+
"mustache": "^4.2.0"
|
|
65
64
|
}
|
|
66
65
|
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Result } from '../base';
|
|
2
|
-
/**
|
|
3
|
-
* Options for {@link Csv.readCsvFileSync}
|
|
4
|
-
* @beta
|
|
5
|
-
*/
|
|
6
|
-
export interface CsvOptions {
|
|
7
|
-
delimiter?: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Reads a CSV file from a supplied path.
|
|
11
|
-
* @param srcPath - Source path from which the file is read.
|
|
12
|
-
* @param options - optional parameters to control the processing
|
|
13
|
-
* @returns The contents of the file.
|
|
14
|
-
* @beta
|
|
15
|
-
*/
|
|
16
|
-
export declare function readCsvFileSync(srcPath: string, options?: CsvOptions): Result<unknown>;
|
|
17
|
-
//# sourceMappingURL=csvHelpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"csvHelpers.d.ts","sourceRoot":"","sources":["../../../src/packlets/csv/csvHelpers.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,MAAM,EAAiB,MAAM,SAAS,CAAC;AAEhD;;;GAGG;AAEH,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CActF"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2020 Erik Fortune
|
|
4
|
-
*
|
|
5
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
* in the Software without restriction, including without limitation the rights
|
|
8
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
* furnished to do so, subject to the following conditions:
|
|
11
|
-
*
|
|
12
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
* copies or substantial portions of the Software.
|
|
14
|
-
*
|
|
15
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
* SOFTWARE.
|
|
22
|
-
*/
|
|
23
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
-
if (k2 === undefined) k2 = k;
|
|
25
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
-
}
|
|
29
|
-
Object.defineProperty(o, k2, desc);
|
|
30
|
-
}) : (function(o, m, k, k2) {
|
|
31
|
-
if (k2 === undefined) k2 = k;
|
|
32
|
-
o[k2] = m[k];
|
|
33
|
-
}));
|
|
34
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
-
}) : function(o, v) {
|
|
37
|
-
o["default"] = v;
|
|
38
|
-
});
|
|
39
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
40
|
-
if (mod && mod.__esModule) return mod;
|
|
41
|
-
var result = {};
|
|
42
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
43
|
-
__setModuleDefault(result, mod);
|
|
44
|
-
return result;
|
|
45
|
-
};
|
|
46
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
exports.readCsvFileSync = void 0;
|
|
48
|
-
const fs = __importStar(require("fs"));
|
|
49
|
-
const papaparse_1 = require("papaparse");
|
|
50
|
-
const path = __importStar(require("path"));
|
|
51
|
-
const base_1 = require("../base");
|
|
52
|
-
/**
|
|
53
|
-
* Reads a CSV file from a supplied path.
|
|
54
|
-
* @param srcPath - Source path from which the file is read.
|
|
55
|
-
* @param options - optional parameters to control the processing
|
|
56
|
-
* @returns The contents of the file.
|
|
57
|
-
* @beta
|
|
58
|
-
*/
|
|
59
|
-
function readCsvFileSync(srcPath, options) {
|
|
60
|
-
return (0, base_1.captureResult)(() => {
|
|
61
|
-
const fullPath = path.resolve(srcPath);
|
|
62
|
-
const body = fs.readFileSync(fullPath, 'utf8').toString();
|
|
63
|
-
options = options !== null && options !== void 0 ? options : {};
|
|
64
|
-
// eslint-disable-next-line
|
|
65
|
-
return (0, papaparse_1.parse)(body, Object.assign({ transform: (s) => s.trim(), header: false, dynamicTyping: false, skipEmptyLines: 'greedy' }, options)).data.slice(1);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
exports.readCsvFileSync = readCsvFileSync;
|
|
69
|
-
//# sourceMappingURL=csvHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"csvHelpers.js","sourceRoot":"","sources":["../../../src/packlets/csv/csvHelpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,yCAAkC;AAClC,2CAA6B;AAC7B,kCAAgD;AAWhD;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,OAAe,EAAE,OAAoB;IACnE,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE;QACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC1D,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;QACxB,2BAA2B;QAC3B,OAAO,IAAA,iBAAK,EAAC,IAAI,kBACf,SAAS,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAClC,MAAM,EAAE,KAAK,EACb,aAAa,EAAE,KAAK,EACpB,cAAc,EAAE,QAAQ,IACrB,OAAO,EACV,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAdD,0CAcC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as fs from 'fs';\nimport { parse } from 'papaparse';\nimport * as path from 'path';\nimport { Result, captureResult } from '../base';\n\n/**\n * Options for {@link Csv.readCsvFileSync}\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface CsvOptions {\n delimiter?: string;\n}\n\n/**\n * Reads a CSV file from a supplied path.\n * @param srcPath - Source path from which the file is read.\n * @param options - optional parameters to control the processing\n * @returns The contents of the file.\n * @beta\n */\nexport function readCsvFileSync(srcPath: string, options?: CsvOptions): Result<unknown> {\n return captureResult(() => {\n const fullPath = path.resolve(srcPath);\n const body = fs.readFileSync(fullPath, 'utf8').toString();\n options = options ?? {};\n // eslint-disable-next-line\n return parse(body, {\n transform: (s: string) => s.trim(),\n header: false,\n dynamicTyping: false,\n skipEmptyLines: 'greedy',\n ...options\n }).data.slice(1);\n });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/csv/index.ts"],"names":[],"mappings":"AAsBA,cAAc,cAAc,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2020 Erik Fortune
|
|
4
|
-
*
|
|
5
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
* in the Software without restriction, including without limitation the rights
|
|
8
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
* furnished to do so, subject to the following conditions:
|
|
11
|
-
*
|
|
12
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
* copies or substantial portions of the Software.
|
|
14
|
-
*
|
|
15
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
* SOFTWARE.
|
|
22
|
-
*/
|
|
23
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
-
if (k2 === undefined) k2 = k;
|
|
25
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
-
}
|
|
29
|
-
Object.defineProperty(o, k2, desc);
|
|
30
|
-
}) : (function(o, m, k, k2) {
|
|
31
|
-
if (k2 === undefined) k2 = k;
|
|
32
|
-
o[k2] = m[k];
|
|
33
|
-
}));
|
|
34
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
35
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
__exportStar(require("./csvHelpers"), exports);
|
|
39
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/csv/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,+CAA6B","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './csvHelpers';\n"]}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Result } from '../base';
|
|
2
|
-
/**
|
|
3
|
-
* An experimental array template which extend built-in `Array` to include a handful
|
|
4
|
-
* of predicates which return {@link Result | Result<T>}.
|
|
5
|
-
* @beta
|
|
6
|
-
*/
|
|
7
|
-
export declare class ExtendedArray<T> extends Array<T> {
|
|
8
|
-
readonly itemDescription: string;
|
|
9
|
-
/**
|
|
10
|
-
* Constructs an {@link Experimental.ExtendedArray}.
|
|
11
|
-
* @param itemDescription - Brief description of the type of each item in this array.
|
|
12
|
-
* @param items - The initial contents of the array.
|
|
13
|
-
*/
|
|
14
|
-
constructor(itemDescription: string, ...items: T[]);
|
|
15
|
-
/**
|
|
16
|
-
* Type guard to determine if some arbitrary array is an
|
|
17
|
-
* {@link Experimental.ExtendedArray}
|
|
18
|
-
* @param a - The `Array` to be tested.
|
|
19
|
-
* @returns Returns `true` if `a` is an {@link Experimental.ExtendedArray},
|
|
20
|
-
* `false` otherwise.
|
|
21
|
-
*/
|
|
22
|
-
static isExtendedArray<T>(a?: T[]): a is ExtendedArray<T>;
|
|
23
|
-
/**
|
|
24
|
-
* Determines if this array contains exactly one element which matches
|
|
25
|
-
* a supplied predicate.
|
|
26
|
-
* @param predicate - The predicate function to be applied.
|
|
27
|
-
* @returns Returns {@link Success | Success<T>} with the single matching
|
|
28
|
-
* result if exactly one item matches `predicate`. Returns {@link Failure}
|
|
29
|
-
* with an error message if there are no matches or more than one match.
|
|
30
|
-
*/
|
|
31
|
-
single(predicate?: (item: T) => boolean): Result<T>;
|
|
32
|
-
/**
|
|
33
|
-
* Returns the first element of an {@link Experimental.ExtendedArray}. Fails with an
|
|
34
|
-
* error message if the array is empty.
|
|
35
|
-
* @param failMessage - Optional message to be displayed in the event of failure.
|
|
36
|
-
* @returns Returns {@link Success | Success<T>} with the value of the first element
|
|
37
|
-
* in the array, or {@link Failure} with an error message if the array is empty.
|
|
38
|
-
*/
|
|
39
|
-
first(failMessage?: string): Result<T>;
|
|
40
|
-
/**
|
|
41
|
-
* Returns an array containing all elements of an {@link Experimental.ExtendedArray}. Fails with
|
|
42
|
-
* an error message if the array is empty.
|
|
43
|
-
* @param failMessage - Optional message to be displayed in the event of failure.
|
|
44
|
-
* @returns Returns {@link Success | Success<T[]>} with a new (non-extended) `Array`
|
|
45
|
-
* containing the elements of this array, or {@link Failure} with an error message
|
|
46
|
-
* if the array is empty.
|
|
47
|
-
*/
|
|
48
|
-
atLeastOne(failMessage?: string): Result<T[]>;
|
|
49
|
-
/**
|
|
50
|
-
* Gets a new (non-extended) `Array` containing all of the elements from this
|
|
51
|
-
* {@link Experimental.ExtendedArray}.
|
|
52
|
-
* @returns A new (non-extended) `Array<T>`.
|
|
53
|
-
*/
|
|
54
|
-
all(): T[];
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=extendedArray.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extendedArray.d.ts","sourceRoot":"","sources":["../../../src/packlets/experimental/extendedArray.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAiB,MAAM,SAAS,CAAC;AAEhD;;;;GAIG;AACH,qBAAa,aAAa,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;IAC5C,SAAgB,eAAe,EAAE,MAAM,CAAC;IAExC;;;;OAIG;gBACgB,eAAe,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE;IAKzD;;;;;;OAMG;WACW,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC;IAIhE;;;;;;;OAOG;IACI,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;IAW1D;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;IAO7C;;;;;;;OAOG;IACI,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC;IAOpD;;;;OAIG;IACI,GAAG,IAAI,CAAC,EAAE;CAGlB"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2020 Erik Fortune
|
|
4
|
-
*
|
|
5
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
* in the Software without restriction, including without limitation the rights
|
|
8
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
* furnished to do so, subject to the following conditions:
|
|
11
|
-
*
|
|
12
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
* copies or substantial portions of the Software.
|
|
14
|
-
*
|
|
15
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
* SOFTWARE.
|
|
22
|
-
*/
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.ExtendedArray = void 0;
|
|
25
|
-
const base_1 = require("../base");
|
|
26
|
-
/**
|
|
27
|
-
* An experimental array template which extend built-in `Array` to include a handful
|
|
28
|
-
* of predicates which return {@link Result | Result<T>}.
|
|
29
|
-
* @beta
|
|
30
|
-
*/
|
|
31
|
-
class ExtendedArray extends Array {
|
|
32
|
-
/**
|
|
33
|
-
* Constructs an {@link Experimental.ExtendedArray}.
|
|
34
|
-
* @param itemDescription - Brief description of the type of each item in this array.
|
|
35
|
-
* @param items - The initial contents of the array.
|
|
36
|
-
*/
|
|
37
|
-
constructor(itemDescription, ...items) {
|
|
38
|
-
super(...items);
|
|
39
|
-
this.itemDescription = itemDescription;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Type guard to determine if some arbitrary array is an
|
|
43
|
-
* {@link Experimental.ExtendedArray}
|
|
44
|
-
* @param a - The `Array` to be tested.
|
|
45
|
-
* @returns Returns `true` if `a` is an {@link Experimental.ExtendedArray},
|
|
46
|
-
* `false` otherwise.
|
|
47
|
-
*/
|
|
48
|
-
static isExtendedArray(a) {
|
|
49
|
-
return a instanceof ExtendedArray;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Determines if this array contains exactly one element which matches
|
|
53
|
-
* a supplied predicate.
|
|
54
|
-
* @param predicate - The predicate function to be applied.
|
|
55
|
-
* @returns Returns {@link Success | Success<T>} with the single matching
|
|
56
|
-
* result if exactly one item matches `predicate`. Returns {@link Failure}
|
|
57
|
-
* with an error message if there are no matches or more than one match.
|
|
58
|
-
*/
|
|
59
|
-
single(predicate) {
|
|
60
|
-
const match = predicate ? this.filter(predicate) : this;
|
|
61
|
-
if (match.length === 1) {
|
|
62
|
-
return (0, base_1.succeed)(match[0]);
|
|
63
|
-
}
|
|
64
|
-
if (match.length === 0) {
|
|
65
|
-
return (0, base_1.fail)(`${this.itemDescription} not found`);
|
|
66
|
-
}
|
|
67
|
-
return (0, base_1.fail)(`${this.itemDescription} matches ${match.length} items`);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Returns the first element of an {@link Experimental.ExtendedArray}. Fails with an
|
|
71
|
-
* error message if the array is empty.
|
|
72
|
-
* @param failMessage - Optional message to be displayed in the event of failure.
|
|
73
|
-
* @returns Returns {@link Success | Success<T>} with the value of the first element
|
|
74
|
-
* in the array, or {@link Failure} with an error message if the array is empty.
|
|
75
|
-
*/
|
|
76
|
-
first(failMessage) {
|
|
77
|
-
if (this.length > 0) {
|
|
78
|
-
return (0, base_1.succeed)(this[0]);
|
|
79
|
-
}
|
|
80
|
-
return (0, base_1.fail)(failMessage !== null && failMessage !== void 0 ? failMessage : `${this.itemDescription} not found`);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Returns an array containing all elements of an {@link Experimental.ExtendedArray}. Fails with
|
|
84
|
-
* an error message if the array is empty.
|
|
85
|
-
* @param failMessage - Optional message to be displayed in the event of failure.
|
|
86
|
-
* @returns Returns {@link Success | Success<T[]>} with a new (non-extended) `Array`
|
|
87
|
-
* containing the elements of this array, or {@link Failure} with an error message
|
|
88
|
-
* if the array is empty.
|
|
89
|
-
*/
|
|
90
|
-
atLeastOne(failMessage) {
|
|
91
|
-
if (this.length > 0) {
|
|
92
|
-
return (0, base_1.succeed)(Array.from(this));
|
|
93
|
-
}
|
|
94
|
-
return (0, base_1.fail)(failMessage !== null && failMessage !== void 0 ? failMessage : `${this.itemDescription} not found`);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Gets a new (non-extended) `Array` containing all of the elements from this
|
|
98
|
-
* {@link Experimental.ExtendedArray}.
|
|
99
|
-
* @returns A new (non-extended) `Array<T>`.
|
|
100
|
-
*/
|
|
101
|
-
all() {
|
|
102
|
-
return Array.from(this);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.ExtendedArray = ExtendedArray;
|
|
106
|
-
//# sourceMappingURL=extendedArray.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extendedArray.js","sourceRoot":"","sources":["../../../src/packlets/experimental/extendedArray.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAgD;AAEhD;;;;GAIG;AACH,MAAa,aAAiB,SAAQ,KAAQ;IAG5C;;;;OAIG;IACH,YAAmB,eAAuB,EAAE,GAAG,KAAU;QACvD,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;QAChB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,eAAe,CAAI,CAAO;QACtC,OAAO,CAAC,YAAY,aAAa,CAAC;IACpC,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,SAAgC;QAC5C,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACxD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACtB,OAAO,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SAC1B;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACtB,OAAO,IAAA,WAAI,EAAC,GAAG,IAAI,CAAC,eAAe,YAAY,CAAC,CAAC;SAClD;QACD,OAAO,IAAA,WAAI,EAAC,GAAG,IAAI,CAAC,eAAe,YAAY,KAAK,CAAC,MAAM,QAAQ,CAAC,CAAC;IACvE,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,WAAoB;QAC/B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACzB;QACD,OAAO,IAAA,WAAI,EAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,GAAG,IAAI,CAAC,eAAe,YAAY,CAAC,CAAC;IAClE,CAAC;IAED;;;;;;;OAOG;IACI,UAAU,CAAC,WAAoB;QACpC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,OAAO,IAAA,cAAO,EAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SAClC;QACD,OAAO,IAAA,WAAI,EAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,GAAG,IAAI,CAAC,eAAe,YAAY,CAAC,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACI,GAAG;QACR,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF;AAhFD,sCAgFC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from '../base';\r\n\r\n/**\r\n * An experimental array template which extend built-in `Array` to include a handful\r\n * of predicates which return {@link Result | Result<T>}.\r\n * @beta\r\n */\r\nexport class ExtendedArray<T> extends Array<T> {\r\n public readonly itemDescription: string;\r\n\r\n /**\r\n * Constructs an {@link Experimental.ExtendedArray}.\r\n * @param itemDescription - Brief description of the type of each item in this array.\r\n * @param items - The initial contents of the array.\r\n */\r\n public constructor(itemDescription: string, ...items: T[]) {\r\n super(...items);\r\n this.itemDescription = itemDescription;\r\n }\r\n\r\n /**\r\n * Type guard to determine if some arbitrary array is an\r\n * {@link Experimental.ExtendedArray}\r\n * @param a - The `Array` to be tested.\r\n * @returns Returns `true` if `a` is an {@link Experimental.ExtendedArray},\r\n * `false` otherwise.\r\n */\r\n public static isExtendedArray<T>(a?: T[]): a is ExtendedArray<T> {\r\n return a instanceof ExtendedArray;\r\n }\r\n\r\n /**\r\n * Determines if this array contains exactly one element which matches\r\n * a supplied predicate.\r\n * @param predicate - The predicate function to be applied.\r\n * @returns Returns {@link Success | Success<T>} with the single matching\r\n * result if exactly one item matches `predicate`. Returns {@link Failure}\r\n * with an error message if there are no matches or more than one match.\r\n */\r\n public single(predicate?: (item: T) => boolean): Result<T> {\r\n const match = predicate ? this.filter(predicate) : this;\r\n if (match.length === 1) {\r\n return succeed(match[0]);\r\n }\r\n if (match.length === 0) {\r\n return fail(`${this.itemDescription} not found`);\r\n }\r\n return fail(`${this.itemDescription} matches ${match.length} items`);\r\n }\r\n\r\n /**\r\n * Returns the first element of an {@link Experimental.ExtendedArray}. Fails with an\r\n * error message if the array is empty.\r\n * @param failMessage - Optional message to be displayed in the event of failure.\r\n * @returns Returns {@link Success | Success<T>} with the value of the first element\r\n * in the array, or {@link Failure} with an error message if the array is empty.\r\n */\r\n public first(failMessage?: string): Result<T> {\r\n if (this.length > 0) {\r\n return succeed(this[0]);\r\n }\r\n return fail(failMessage ?? `${this.itemDescription} not found`);\r\n }\r\n\r\n /**\r\n * Returns an array containing all elements of an {@link Experimental.ExtendedArray}. Fails with\r\n * an error message if the array is empty.\r\n * @param failMessage - Optional message to be displayed in the event of failure.\r\n * @returns Returns {@link Success | Success<T[]>} with a new (non-extended) `Array`\r\n * containing the elements of this array, or {@link Failure} with an error message\r\n * if the array is empty.\r\n */\r\n public atLeastOne(failMessage?: string): Result<T[]> {\r\n if (this.length > 0) {\r\n return succeed(Array.from(this));\r\n }\r\n return fail(failMessage ?? `${this.itemDescription} not found`);\r\n }\r\n\r\n /**\r\n * Gets a new (non-extended) `Array` containing all of the elements from this\r\n * {@link Experimental.ExtendedArray}.\r\n * @returns A new (non-extended) `Array<T>`.\r\n */\r\n public all(): T[] {\r\n return Array.from(this);\r\n }\r\n}\r\n"]}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Result } from '../base';
|
|
2
|
-
/**
|
|
3
|
-
* Destination format for some formatted string.
|
|
4
|
-
* @beta
|
|
5
|
-
*/
|
|
6
|
-
export type FormatTargets = 'text' | 'markdown' | 'embed';
|
|
7
|
-
/**
|
|
8
|
-
* Interface for an object that can be formatted.
|
|
9
|
-
* @beta
|
|
10
|
-
*/
|
|
11
|
-
export interface Formattable {
|
|
12
|
-
/**
|
|
13
|
-
* Formats an object using the supplied mustache template.
|
|
14
|
-
* @param format - A mustache template used to format the object.
|
|
15
|
-
* @returns {@link Success} with the resulting string, or {@link Failure}
|
|
16
|
-
* with an error message if an error occurs.
|
|
17
|
-
*/
|
|
18
|
-
format(format: string): Result<string>;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Base class which adds common formatting.
|
|
22
|
-
* @beta
|
|
23
|
-
*/
|
|
24
|
-
export declare class FormattableBase {
|
|
25
|
-
/**
|
|
26
|
-
* Helper enables derived classes to add named details to a formatted presentation.
|
|
27
|
-
* @param details - An array of detail description strings.
|
|
28
|
-
* @param label - Label to use for the new detail.
|
|
29
|
-
* @param value - Value to use for the new detail.
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
protected static _tryAddDetail(details: string[], label: string, value: string | undefined): void;
|
|
33
|
-
/**
|
|
34
|
-
* {@inheritdoc Experimental.Formattable.format}
|
|
35
|
-
*/
|
|
36
|
-
format(template: string): Result<string>;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Type definition for a formatting function, which takes a `string` and an
|
|
40
|
-
* item and returns {@link Result | Result<string>}.
|
|
41
|
-
* @beta
|
|
42
|
-
*/
|
|
43
|
-
export type Formatter<T> = (format: string, item: T) => Result<string>;
|
|
44
|
-
/**
|
|
45
|
-
* A collection of {@link Experimental.Formatter | formatters} indexed by target name, to enable
|
|
46
|
-
* different format methods per output target.
|
|
47
|
-
* @beta
|
|
48
|
-
*/
|
|
49
|
-
export type FormattersByExtendedTarget<TFT extends FormatTargets, T> = Record<TFT, Formatter<T>>;
|
|
50
|
-
/**
|
|
51
|
-
* A collection of {@link Experimental.Formatter | formatters} indexed by the
|
|
52
|
-
* {@link Experimental.FormatTargets | default supported target formats}.
|
|
53
|
-
* @beta
|
|
54
|
-
*/
|
|
55
|
-
export type FormattersByTarget<T> = FormattersByExtendedTarget<FormatTargets, T>;
|
|
56
|
-
/**
|
|
57
|
-
* Formats a list of items using the supplied template and formatter, one result
|
|
58
|
-
* per output line.
|
|
59
|
-
* @param format - A mustache template used to format each item.
|
|
60
|
-
* @param items - The items to be formatted.
|
|
61
|
-
* @param itemFormatter - The {@link Experimental.Formatter | Formatter<T>} used to format each item.
|
|
62
|
-
* @returns The resulting string.
|
|
63
|
-
* @beta
|
|
64
|
-
*/
|
|
65
|
-
export declare function formatList<T>(format: string, items: T[], itemFormatter: Formatter<T>): Result<string>;
|
|
66
|
-
//# sourceMappingURL=formatter.d.ts.map
|