Skip to content

Commit 4b22d4d

Browse files
committed
formatting
1 parent 5b897ee commit 4b22d4d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

demo-ts/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ import CSVFileValidator, { ParsedResults, ValidatorConfig } from '../src/csv-fil
33
const requiredError = (headerName: string, rowNumber: number, columnNumber: number) => {
44
return `<div class="red">${headerName} is required in the <strong>${rowNumber} row</strong> / <strong>${columnNumber} column</strong></div>`
55
}
6+
67
const validateError = (headerName: string, rowNumber: number, columnNumber: number) => {
78
return `<div class="red">${headerName} is not valid in the <strong>${rowNumber} row</strong> / <strong>${columnNumber} column</strong></div>`
89
}
10+
911
const uniqueError = (headerName: string, rowNumber: number) => {
1012
return `<div class="red">${headerName} is not unique at the <strong>${rowNumber} row</strong></div>`
1113
}
14+
1215
const isEmailValid = function (email: string) {
1316
const reqExp = /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$/
1417
return reqExp.test(email)
1518
}
19+
1620
const isPasswordValid = function (password: string) {
1721
return password.length >= 4
1822
}

demo/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ import CSVFileValidator from '../src/csv-file-validator'
33
const requiredError = (headerName, rowNumber, columnNumber) => {
44
return `<div class="red">${headerName} is required in the <strong>${rowNumber} row</strong> / <strong>${columnNumber} column</strong></div>`
55
}
6+
67
const validateError = (headerName, rowNumber, columnNumber) => {
78
return `<div class="red">${headerName} is not valid in the <strong>${rowNumber} row</strong> / <strong>${columnNumber} column</strong></div>`
89
}
10+
911
const uniqueError = (headerName, rowNumber) => {
1012
return `<div class="red">${headerName} is not unique at the <strong>${rowNumber} row</strong></div>`
1113
}
14+
1215
const isEmailValid = function (email) {
1316
const reqExp = /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$/
1417
return reqExp.test(email)
1518
}
19+
1620
const isPasswordValid = function (password) {
1721
return password.length >= 4
1822
}

src/csv-file-validator.d.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
1-
// Type definitions for csv-file-validator 1.10
1+
// Type definitions for csv-file-validator 1.11
22
// Project: https://github.com/shystruk/csv-file-validator
33
// Definitions by: Igor Levkov <https://github.com/igors-levkovs>
44
/// <reference types="node" />
55

66
export interface FieldSchema<Error = string> {
77
/** Name of the row header (title) */
88
name: string;
9+
910
/** Key name which will be return with value in a column */
1011
inputName: string;
12+
1113
/** Makes column optional. If true column value will be return */
1214
optional?: boolean;
15+
1316
/** If required is true than a column value will be checked if it is not empty */
1417
required: boolean;
18+
1519
/** If it is true all header (title) column values will be checked for uniqueness */
1620
unique?: boolean;
21+
1722
/** If column contains list of values separated by comma in return object it will be as an array */
1823
isArray?: boolean;
24+
1925
/** If a header name is omitted or is not the same as in config name headerError function will be called with arguments headerName */
2026
headerError?: (headerValue: string, headerName: string, rowNumber: number, columnNumber: number) => Error;
27+
2128
/** If value is empty requiredError function will be called with arguments headerName, rowNumber, columnNumber */
2229
requiredError?: (headerName: string, rowNumber: number, columnNumber: number) => Error;
30+
2331
/** If one of the header value is not unique uniqueError function will be called with argument headerName */
2432
uniqueError?: (headerName: string, rowNumber: number) => Error;
33+
2534
/** Validate column value. Must return true for valid field and false for invalid */
2635
validate?: (field: string) => boolean;
36+
2737
/** If validate returns false validateError function will be called with arguments headerName, rowNumber, columnNumber */
2838
validateError?: (headerName: string, rowNumber: number, columnNumber: number) => Error;
2939
}
@@ -44,4 +54,4 @@ export interface ValidatorConfig<Error = string> {
4454
export default function CSVFileValidator<Row = any, Error = string>(
4555
csv: string | File | NodeJS.ReadableStream,
4656
config: ValidatorConfig<Error>
47-
): Promise<ParsedResults<Row, Error>>;
57+
): Promise<ParsedResults<Row, Error>>;

0 commit comments

Comments
 (0)