Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
ts: mark info as readonly with required properties
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 12, 2018
1 parent 7556d4f commit 6fa5a35
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -30,6 +30,7 @@ New features:
* delimiter: handle multiple bytes/characters
* callback: export info object as third argument
* cast: catch error in user functions
* ts: mark info as readonly with required properties

API management

Expand Down
16 changes: 8 additions & 8 deletions lib/index.d.ts
Expand Up @@ -187,20 +187,20 @@ declare namespace parse {

interface Info {
/**
*
* Count the number of processed empty lines.
*/
empty_lines?: number;
readonly empty_lines: number;
/**
*
* The number of lines encountered in the source dataset, start at 1 for the first line.
*/
lines?: number;
readonly lines: number;
/**
*
* Count the number of processed records.
*/
records?: number;
readonly records: number;
/**
*
* Number of non uniform records when `relax_column_count` is true.
*/
invalid_field_length?: number;
readonly invalid_field_length: number;
}
}
28 changes: 19 additions & 9 deletions test/api.types.ts
Expand Up @@ -25,32 +25,42 @@ describe('API Types', () => {
const info: Info = parser.info
const keys: any = Object.keys(info)
keys.sort().should.eql([
'empty_lines', 'invalid_field_length', 'lines', 'records'
'empty_lines', 'invalid_field_length',
'lines', 'records'
])
})

})

describe('Info', () => {

const fakeinfo = {
empty_lines: 1, invalid_field_length: 1,
lines: 1, records: 1
}

it('empty_lines', () => {
const info: Info = {}
info.empty_lines = 1
const info: Info = fakeinfo
const empty_lines: number = info.empty_lines
empty_lines
})

it('lines', () => {
const info: Info = {}
info.lines = 1
const info: Info = fakeinfo
const lines: number = info.lines
lines
})

it('records', () => {
const info: Info = {}
info.records = 1
const info: Info = fakeinfo
const records: number = info.records
records
})

it('invalid_field_length', () => {
const info: Info = {}
info.invalid_field_length = 1
const info: Info = fakeinfo
const invalid_field_length: number = info.invalid_field_length
invalid_field_length
})

})
Expand Down

0 comments on commit 6fa5a35

Please sign in to comment.