Skip to content

Commit

Permalink
feat: get raw data directly on the class
Browse files Browse the repository at this point in the history
  • Loading branch information
tale committed Jan 22, 2022
1 parent 2c273d6 commit 4e48eec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test('release:chariz', async () => {
const data = await readFile('test/chariz.release', 'utf8')
const release = new Release(data)

expect(release.raw.size).toEqual(11)
expect(release.fieldCount).toEqual(11)
expect(release.architectures).toEqual(expect.arrayContaining(['iphoneos-arm']))
expect(release.noSupportForArchitectureAll).toBeUndefined()
expect(release.description).toEqual('Check out what’s new and download purchases from the Chariz marketplace!')
Expand Down Expand Up @@ -36,7 +36,7 @@ test('release:jammy', async () => {
const data = await readFile('test/jammy.release', 'utf8')
const release = new Release(data)

expect(release.raw.size).toEqual(13)
expect(release.fieldCount).toEqual(13)
expect(release.architectures).toEqual(expect.arrayContaining([
'amd64',
'arm64',
Expand Down
24 changes: 19 additions & 5 deletions src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ type ReleaseHash = {
* It will populate the strictly typed fields and also leave the raw-string value and key.
*/
export class Release {
/**
* Raw key-value map of Release fields
*/
raw: Map<string, string>
private raw: Map<string, string>

/**
* Parsed array of strings depicting the supported architectures.
Expand Down Expand Up @@ -274,10 +271,27 @@ export class Release {
}
}

/**
* Get a raw string value from the Release contents
* @param {string} key Release field name to search for
* @returns {string?} Field value
*/
get(key: string): string | undefined {
return this.raw.get(key)
}

/**
* Retrieve the number of fields defined in the Release contents
* @returns {number} Field count
*/
get fieldCount(): number {
return this.raw.size
}

/**
* Convert APT Release hash keys to the appropriate ones on this class
* @param {string} key Release hash key
* @returns {string} Class property name
* @returns {string?} Class property name
*/
private getHashIndex(key: string): string | undefined {
switch (key) {
Expand Down

0 comments on commit 4e48eec

Please sign in to comment.