datakit
- IColumnFormatterConfig
- IColumnParserConfig
- ICsvInputConfig
- ICsvOutputConfig
- IFieldDesc
- IFieldFormatterConfig
- IFieldParserConfig
- IJsonInputConfig
- IJsonOutputConfig
- fromCsv
- fromJson
- fromObject
- fromYaml
- readCsv
- readCsvSync
- readFile
- readJson
- readJsonSync
- readYaml
- readYamlSync
- toCsv
- toJson
- toYaml
- writeCsv
- writeCsvSync
- writeFile
- writeJson
- writeJsonSync
- writeYaml
- writeYamlSync
▸ fromCsv<RecordT
>(csvTextString
, config?
): RecordT
[]
Deserialize CSV text to a JavaScript array. Each element of the array contains fields that match the columns from the CSV data.
Name |
---|
RecordT |
Name | Type | Description |
---|---|---|
csvTextString |
string |
The CSV text to deserialize. |
config? |
ICsvInputConfig |
Optional configuration options for parsing the CSV data. |
RecordT
[]
Returns an array of JavaScript objects that were deserialized from the CSV text.
▸ fromJson<RecordT
>(jsonTextString
, config?
): RecordT
[]
Deserialize JSON text to a JavaScript array.
Name |
---|
RecordT |
Name | Type | Description |
---|---|---|
jsonTextString |
string |
The JSON text to deserialize. |
config? |
IJsonInputConfig |
- |
RecordT
[]
Returns an array of JavaScript objects that were deserialized from the JSON text.
▸ fromObject(obj
): IFieldDesc
[]
Convert a regular JavaScript object to 'tablular data'. Each element of the matches a field from the object.
Name | Type | Description |
---|---|---|
obj |
any |
The JavaScript object to convert to a dataframe. |
Returns an array with an element describing each field.
▸ fromYaml<RecordT
>(yamlTextString
): RecordT
[]
Deserialize YAML text to a JavaScript array.
Name |
---|
RecordT |
Name | Type | Description |
---|---|---|
yamlTextString |
string |
The YAML text to deserialize. |
RecordT
[]
Returns an array of JavaScript objects that were deserialized from the YAML text.
▸ readCsv<RecordT
>(filePath
, config?
): Promise
<RecordT
[]>
Asynchronously deserialize a CSV file to a JavaScript array. Each element of the array contains fields that match the columns from the CSV file.
Example
<pre>
const data = await datakit.readCsv("my-data-file.csv");
console.log(data);
</pre>
const config = {
dynamicTyping: true,
// ... other options ...
};
const data = await datakit.readCsv("my-data-file.csv", config);
console.log(data);
</pre>
Name |
---|
RecordT |
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be loaded. |
config? |
ICsvInputConfig |
Optional configuration file for parsing. |
Promise
<RecordT
[]>
Returns a promise for the loaded data.
▸ readCsvSync<RecordT
>(filePath
, config?
): RecordT
[]
Synchronously deserialize a CSV file to a JavaScript array. Each element of the array contains fields that match the columns from the CSV file.
Example
<pre>
const data = datakit.readCsvSync("my-data-file.csv");
console.log(data);
</pre>
Example
<pre>
const config = {
dynamicTyping: true,
// ... other options ...
};
const data = datakit.readCsvSync("my-data-file.csv", config);
console.log(data);
</pre>
Name |
---|
RecordT |
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be loaded. |
config? |
ICsvInputConfig |
Optional configuration file for parsing. |
RecordT
[]
Returns the loaded data.
▸ readFile(filePath
): Promise
<string
>
Like fs.readFile but returns a promise for the file data.
Example
<pre>
const data = await datakit.readFile("some-data-file.txt");
console.log(data);
</pre>
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be loaded. |
Promise
<string
>
A promise that is resolved with the contents of the file.
▸ readJson<RecordT
>(filePath
): Promise
<RecordT
[]>
Asynchronously deserialize a JSON file to a JavaScript array.
Example
<pre>
const data = await datakit.readJson("my-data-file.json");
console.log(data);
</pre>
Name |
---|
RecordT |
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be loaded. |
Promise
<RecordT
[]>
Returns a promise for the loaded data.
▸ readJsonSync<RecordT
>(filePath
): RecordT
[]
Synchronously deserialize a JSON file to a JavaScript array.
Example
<pre>
const data = datakit.readJsonSync("my-data-file.json");
console.log(data);
</pre>
Name |
---|
RecordT |
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be loaded. |
RecordT
[]
Returns the loaded data.
▸ readYaml<RecordT
>(filePath
): Promise
<RecordT
[]>
Asynchronously deserialize a YAML file to a JavaScript array.
Example
<pre>
const data = await datakit.readYaml("my-data-file.yaml");
console.log(data);
</pre>
Name |
---|
RecordT |
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be loaded. |
Promise
<RecordT
[]>
Returns a promise for the loaded data.
▸ readYamlSync<RecordT
>(filePath
): RecordT
[]
Synchronously deserialize a YAML file to a JavaScript array.
Example
<pre>
const data = datakit.readYamlSync("my-data-file.yaml");
console.log(data);
</pre>
Name |
---|
RecordT |
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be loaded. |
RecordT
[]
Returns the loaded data.
▸ toCsv(input
, config?
): string
Serialize a JavaScript array to the CSV data format. Columns in the CSV file match fields from the objects in the array.
Example
<pre>
const data = [ ... JavaScript array of data ... ];
const csvData = datakit.toCsv(data);
console.log(csvData);
</pre>
Example
<pre>
const data = [ ... JavaScript array of data ... ];
const config = {
header: false,
// ... other options ...
};
const csvData = datakit.toCsv(data, config);
console.log(csvData);
</pre>
Name | Type | Description |
---|---|---|
input |
any [] |
The data to be serialized. |
config? |
ICsvOutputConfig |
- |
string
Returns a string in the CSV data format that represents the data.
▸ toJson(input
, config?
): string
Serialize a JavaScript array to the JSON data format.
Example
<pre>
const data = ... JavaScript data ...;
const jsonData = datakit.toJson(data);
console.log(jsonData);
</pre>
Name | Type | Description |
---|---|---|
input |
any [] |
The data to be serialized. |
config? |
IJsonOutputConfig |
- |
string
Returns a string in the JSON data format that represents the data.
▸ toYaml(input
): string
Serialize a JavaScript array to the YAML data format.
Example
<pre>
const data = [ ... JavaScript array of data ... ];
const yamlData = datakit.toYaml(data);
console.log(yamlData);
</pre>
Name | Type | Description |
---|---|---|
input |
any [] |
The data to be serialized. |
string
Returns a string in the YAML data format that represents the data.
▸ writeCsv(filePath
, input
, config?
): Promise
<void
>
Asynchronously serialize a JavaScript array to a CSV file. The fields in the objects of the array become the columns in the CSV file.
Example
<pre>
const data = [ ... JavaScript array of data ... ];
await datakit.writeCsv("my-data-file.csv", data);
</pre>
Example
<pre>
const config = {
// ... Options for serialization ...
};
const data = [ ... JavaScript array of data ... ];
await datakit.writeCsv("my-data-file.csv", config);
</pre>
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be written. |
input |
any [] |
- |
config? |
ICsvOutputConfig |
Optional configuration file for parsing. |
Promise
<void
>
Returns a promise that resolves when the file has been written.
▸ writeCsvSync(filePath
, input
, config?
): void
Synchronously serialize a JavaScript array to a CSV file. The fields in the objects of the array become the columns in the CSV file.
Example
<pre>
const data = [ ... JavaScript array of data ... ];
datakit.writeCsvSync("my-data-file.csv", data);
</pre>
Example
<pre>
const config = {
// ... Options for serialization ...
};
const data = [ ... JavaScript array of data ... ];
datakit.writeCsvSync("my-data-file.csv", config);
</pre>
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be written. |
input |
any [] |
- |
config? |
ICsvOutputConfig |
Optional configuration file for parsing. |
void
▸ writeFile(filePath
, data
): Promise
<void
>
Like fs.writeFile but returns a promise for completion of the asynchronous file write.
Example
<pre>
const data = "... JavaScript string with text data ...";
await datakit.writeFile("some-data-file.txt", data);
</pre>
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be written. |
data |
string |
Data to be written the to file. |
Promise
<void
>
A promise that is resolved when the file has been written.
▸ writeJson(filePath
, input
): Promise
<void
>
Asynchronously serialize a JavaScript array to a JSON file.
Example
<pre>
const data = [ ... JavaScript array of data ... ];
await datakit.writeJson("my-data-file.json", data);
</pre>
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be written. |
input |
any [] |
- |
Promise
<void
>
Returns a promise that resolves when the file has been written.
▸ writeJsonSync(filePath
, input
): void
Synchronously serialize a JavaScript array to a JSON file.
Example
<pre>
const data = [ ... JavaScript array of data ... ];
datakit.writeJsonSync("my-data-file.json", data);
</pre>
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be written. |
input |
any [] |
- |
void
Returns a promise that resolves when the file has been written.
▸ writeYaml(filePath
, input
): Promise
<void
>
Asynchronously serialize a JavaScript array to a YAML file.
Example
<pre>
const data = [ ... JavaScript array of data ... ];
await datakit.writeYaml("my-data-file.yaml", data);
</pre>
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be written. |
input |
any [] |
- |
Promise
<void
>
Returns a promise that resolves when the file has been written.
▸ writeYamlSync(filePath
, input
): void
Synchronously serialize a JavaScript array to a Yaml file.
Example
<pre>
const data = [ ... JavaScript array of data ... ];
datakit.writeYamlSync("my-data-file.yaml", data);
</pre>
Name | Type | Description |
---|---|---|
filePath |
string |
Path to the file to be written. |
input |
any [] |
- |
void
Returns a promise that resolves when the file has been written.