Skip to content

Commit 0218e46

Browse files
author
Irene Alvarado
committed
Detail API for each function
1 parent 6a7dcc3 commit 0218e46

File tree

1 file changed

+267
-8
lines changed

1 file changed

+267
-8
lines changed

README.md

Lines changed: 267 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,290 @@ You can import and use these helper functions directly, or treat them as a start
5656

5757
### CSV
5858

59-
TBD API
59+
#### readCSV
60+
61+
```ts
62+
readCSV(path: string, options?: ParseOptions): Promise<Record<string, unknown>[]>
63+
```
64+
65+
Args:
66+
67+
* **path:** path to a local CSV file
68+
* **options:** [options](https://deno.land/[email protected]/encoding#codeparseoptionscode) for parsing the CSV file
69+
70+
Usage:
71+
72+
`const csv = await readCSV('./path/to/file.csv')`
73+
74+
#### writeCSV
75+
76+
```ts
77+
writeCSV(path: string, data: Record<string, unknown>[] | string)
78+
```
79+
80+
Args:
81+
82+
* **path**: path to a local CSV file
83+
* **data**: string or object array to store
84+
85+
Usage:
86+
87+
```ts
88+
const data = [
89+
{ age: 70, name: 'Rick' },
90+
{ age: 14, name: 'Smith' }
91+
]
92+
await writeCSV('./path/to/file.csv', data)
93+
```
6094

6195
### TXT
6296

63-
TBD API
97+
#### readTXT
98+
99+
```ts
100+
readTXT(path: string): string
101+
```
102+
103+
Args:
104+
105+
* **path**: path to a local TXT file
106+
107+
108+
Usage:
109+
110+
```ts
111+
const text = await readTXT('./path/to/file.txt')
112+
```
113+
114+
#### writeTXT
115+
116+
```ts
117+
writeTXT(path: string, text: string): void
118+
```
119+
120+
Args:
121+
122+
* **path**: path to a local TXT file
123+
* **text**: text to write to file
124+
125+
126+
Usage:
127+
128+
```ts
129+
await writeTXT('./path/to/file.txt', 'Content for the file')
130+
```
64131

65132
### JSON
66133

67-
TBD API
134+
135+
#### readJSON
136+
137+
```ts
138+
readJSON(path: string): JSON
139+
```
140+
141+
Args:
142+
143+
* **path**: path to a local JSON file
144+
145+
146+
Usage:
147+
148+
```ts
149+
const json = await readJSON('./path/to/file.json')
150+
```
151+
152+
#### readJSONFromURL
153+
154+
```ts
155+
readJSONFromURL(url: string): JSON
156+
```
157+
158+
Args:
159+
160+
* **url**: URL to a json file
161+
162+
163+
Usage:
164+
165+
```ts
166+
const json = await readJSON('www.url.com/file.json')
167+
```
168+
169+
#### writeJSON
170+
171+
```ts
172+
writeJSON(path: string, data: any): void
173+
```
174+
175+
Args:
176+
177+
* **path**: path to a local JSON file
178+
* **data**: data to store as JSON
179+
180+
Usage:
181+
182+
```ts
183+
const data = { age: 40 }
184+
await writeJSON('./path/to/file.json', data)
185+
```
68186

69187
### XLSX
70188

71-
TBD API
189+
Our library relies on [SheetJS](https://github.com/SheetJS/sheetjs), a library for parsing various spreadsheet formats. In addition to a simple `readXLSX` function you can access the core `xlsx` module by importing it directly.
190+
191+
```ts
192+
import { xlsx, readXLSX } from 'https://deno.land/x/flat/mod.ts'
193+
```
194+
195+
`xlsx` provides many more [utility functions](https://github.com/SheetJS/sheetjs).
196+
197+
198+
#### readXLSX
199+
200+
```ts
201+
readXLSX(path: string): XLSX.WorkBook
202+
```
203+
204+
Args:
205+
206+
* **path**: path to a local XLSX file
207+
208+
209+
Usage:
210+
211+
```ts
212+
const workbook = await readXLSX('./path/to/file.xlsx')
213+
const sheetData = workbook.Sheets[workbook.SheetNames[0]]
214+
const csvString = await xlsx.utils.sheet_to_csv(sheetData)
215+
```
216+
72217

73218
### Image
74219

75-
TBD API
220+
We recommend using a library like [imagescript](https://deno.land/x/imagescript) for more advanced image manipulation. See an example [here](https://github.com/githubocto/flat-postprocessing/blob/main/examples/image/image-example.ts).
221+
222+
#### readImageFromFile
223+
224+
```ts
225+
readImageFromFile(path: string): Promise<Uint8Array>
226+
```
227+
228+
Args:
229+
230+
* **path**: path to a local image file
231+
232+
233+
Usage:
234+
235+
```ts
236+
const bytes = await readImageFromFile('./path/to/image.jpeg')
237+
```
238+
239+
240+
#### readImageFromURL
241+
242+
```ts
243+
readImageFromURL(url: string): Promise<{ bytes: Uint8Array; name: string; }>
244+
```
245+
246+
Args:
247+
248+
* **url**: url string to an image
249+
250+
Usage:
251+
252+
```ts
253+
const image = await readImageFromURL('www.url.com/image.jpg')
254+
const bytes = image.bytes
255+
const name = image.name
256+
```
257+
258+
#### writeImage
259+
260+
```ts
261+
writeImage(imageBytes: Uint8Array, path: string): void
262+
```
263+
264+
Args:
265+
266+
* **imageBytes:** a byte array
267+
* **path:** path and name to write the image file
268+
269+
270+
Usage:
271+
272+
```ts
273+
await writeImage(bytes, './path/to/image.jpeg')
274+
```
76275

77276
### Zip
78277

79-
TBD API
278+
#### unZipFromFile
279+
280+
```ts
281+
unZipFromFile(
282+
filePath: string,
283+
destinationPath: string | null = "./",
284+
options: any = {},
285+
): Promise<string | false>
286+
```
287+
288+
Args:
289+
290+
* **filePath:**: a path to a local zip file
291+
* **destinationPath:**: a folder path to unzip the files
292+
* **options:**: option.includeFileName can be true or false
293+
294+
295+
Usage:
296+
297+
```ts
298+
const result = await unZipFromFile('./path/to/folder.zip', './unzip/path')
299+
const output = result ? 'File unzipped successfully' : 'Error unzipping'
300+
```
301+
302+
#### unZipFromURL
303+
```ts
304+
unZipFromURL(
305+
fileURL: string,
306+
destinationPath: string | null = "./",
307+
options: any = {},
308+
): Promise<string | false>
309+
```
310+
311+
Args:
312+
313+
* **filePath:**: a path to a local zip file
314+
* **destinationPath:**: a folder path to unzip the files
315+
* **options:**: option.includeFileName can be true or false
316+
317+
Usage:
318+
319+
```ts
320+
const result = await unZipFromURL('www.url.com/file.zip', './unzip/path')
321+
const output = result ? 'File unzipped successfully' : 'Error unzipping'
322+
```
323+
80324

81325
### Remove
82326

83-
TBD API
327+
#### removeFile
328+
329+
```ts
330+
removeFile(path: string): void
331+
```
332+
333+
Args:
334+
335+
* **path**: path to a local file to delete
336+
337+
338+
Usage:
339+
340+
```ts
341+
await removeFile('/path/to/file.x')
342+
```
84343

85344
## Testing
86345

@@ -90,7 +349,7 @@ Run all the tests:
90349

91350
Run separate tests
92351

93-
`deno test -A tests/csv-test.ts`
352+
`deno test -A --unstable tests/csv-test.ts`
94353

95354

96355
## License

0 commit comments

Comments
 (0)