Skip to content

Commit

Permalink
chore: document older methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tale committed Feb 14, 2022
1 parent c362636 commit 404cdd1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export * from './release'
export * from 'release'

/**
* Parse raw file contents that conform to the APT key-value format
* @param data Raw data
* @returns A key-value map of raw-value strings
*/
export function parseKV(data: string) {
const cleanedData = data.replaceAll(/\r\n|\r|\n/g, '\n').replaceAll(/\0/g, '').normalize().trim()
const lineChunks = cleanedData.split('\n') // We know it will always be \n because of our cleanup
Expand Down Expand Up @@ -59,12 +64,24 @@ export function parseKV(data: string) {
return fields
}

/**
* Parse raw file contents of a packages file and retrieve a map of keys and values
*
* @param data Raw string contents from a Packages file
* @returns Map of string keys and values
*/
export function parsePackages(data: string) {
const cleanedData = data.replaceAll(/\r\n|\r|\n/g, '\n').replaceAll(/\0/g, '').normalize().trim()
const packageChunks = cleanedData.split('\n\n') // We know it will always be \n\n because of our cleanup
return packageChunks.map(chunk => parseKV(chunk))
}

/**
* Parse raw file contents of a control file and retrieve a map of keys and values
*
* @param data Raw string contents from a control file
* @returns Map of string keys and values
*/
export function parseControl(data: string) {
return parsePackages(data)
}
Expand Down

0 comments on commit 404cdd1

Please sign in to comment.