@pbkware/fielded-text-web 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/package.json +8 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PBKware
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Fielded Text TypeScript Library (for web)
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@pbkware/fielded-text-web) [](https://github.com/pbkware/fielded-text-web/blob/main/LICENSE)
|
|
4
|
+
|
|
5
|
+
This library allows you to parse and generate CSV like text data in manner similar to reading and writing from/to databases. It does this by associating a schema (called Meta) with the text data.
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
The structure of this meta/schema is specified by the proposed [Fielded Text](https://fieldedtext.org/) standard. Note that this standard is not limited to CSV data but handles a [wide variety](https://fieldedtext.org/introduction/capabilities/) of text data where lines consist of field values. For example it can also be used with lines having fixed width fields and also with lines containing different fields based on the value of key fields.
|
|
10
|
+
|
|
11
|
+
Below is a very simple parsing example:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { FtReader, FtXmlMetaSerialization } from "@pbkware/fielded-text-web";
|
|
15
|
+
|
|
16
|
+
// CSV data to be read
|
|
17
|
+
const csvData = `Name,Age
|
|
18
|
+
John Doe,30
|
|
19
|
+
Jane Smith,25`;
|
|
20
|
+
|
|
21
|
+
// Meta describing the schema of the CSV data
|
|
22
|
+
const xmlMeta = `<?xml version="1.0" encoding="utf-8"?>
|
|
23
|
+
<FieldedText HeadingLineCount="1">
|
|
24
|
+
<Field Name="Name"/>
|
|
25
|
+
<Field Name="Age" DataType="Integer"/>
|
|
26
|
+
</FieldedText>`;
|
|
27
|
+
|
|
28
|
+
// Load meta data from XML
|
|
29
|
+
const metaReader = new FtXmlMetaSerialization();
|
|
30
|
+
const meta = metaReader.deserialize(xmlMeta);
|
|
31
|
+
|
|
32
|
+
const reader = new FtReader(meta, csvData);
|
|
33
|
+
|
|
34
|
+
// Read and log the data
|
|
35
|
+
while (reader.read()) {
|
|
36
|
+
console.log(
|
|
37
|
+
reader.fieldList.get(0).asString,
|
|
38
|
+
reader.fieldList.get(1).asBigInt,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm install @pbkware/fielded-text-web
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## More information
|
|
50
|
+
|
|
51
|
+
- **[Guides](https://pbkware.github.io/fielded-text-web/Guides/)**
|
|
52
|
+
- [Getting Started](https://pbkware.github.io/fielded-text-web/Guides/Getting_Started/)
|
|
53
|
+
- [Meta data](https://pbkware.github.io/fielded-text-web/Guides/Meta_data/)
|
|
54
|
+
- **[Examples](#examples)** - Small examples that demonstrate various capabilities
|
|
55
|
+
- **[Fielded Text Website](https://fieldedtext.org/)** - Overview of Fielded Text standard
|
|
56
|
+
- **[Fielded Text Standard](https://fieldedtext.org/standard/)** - The official specification (v0.9)
|
|
57
|
+
|
|
58
|
+
## Examples
|
|
59
|
+
|
|
60
|
+
The examples directory in the source repository contains practical demonstrations:
|
|
61
|
+
|
|
62
|
+
| Example | Description |
|
|
63
|
+
| ---------------------------------------------------------------- | ----------------------------------------------- |
|
|
64
|
+
| basic-read-build-meta | Read CSV by building metadata in code |
|
|
65
|
+
| basic-read-load- meta | Read CSV by loading XML metadata |
|
|
66
|
+
| basic-write | Write CSV with automatic quoting |
|
|
67
|
+
| build-meta-with-sequences | Build metadata for files with sequences |
|
|
68
|
+
| count-records | Efficiently count records without reading data |
|
|
69
|
+
| read-events | Use event hooks during reading |
|
|
70
|
+
| read-sequence | Read files with sequences (conditional fields) |
|
|
71
|
+
| read-sequence-ordinal | Read sequences using ordinals for performance |
|
|
72
|
+
| sequences-with-readback | Work with repeating groups |
|
|
73
|
+
| write-comments | Add comment lines to output |
|
|
74
|
+
| write-declared | Create files with declaration headers |
|
|
75
|
+
| write-events | Use event hooks during writing |
|
|
76
|
+
| write-headings | Write heading lines |
|
|
77
|
+
| write-sequence | Write files with sequences (conditional fields) |
|
|
78
|
+
| write-sequence-events | Write sequences using event-driven approach |
|
|
79
|
+
|
|
80
|
+
### Running Examples
|
|
81
|
+
|
|
82
|
+
From within the examples directory:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Run all examples
|
|
86
|
+
npm run all
|
|
87
|
+
|
|
88
|
+
# Run individual example
|
|
89
|
+
npm run basic-write
|
|
90
|
+
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pbkware/fielded-text-web",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "A library
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "A parser/generator library based on Fielded Text.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"engines": {
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"dist/**/*",
|
|
18
18
|
"src/**/*.ts",
|
|
19
19
|
"src/**/*.json",
|
|
20
|
-
"
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
21
22
|
],
|
|
22
23
|
"homepage": "https://pbkware.github.io/fielded-text-web/",
|
|
23
24
|
"repository": {
|
|
@@ -58,7 +59,10 @@
|
|
|
58
59
|
"prettier": "npx prettier --write .",
|
|
59
60
|
"docs": "typedoc",
|
|
60
61
|
"docs:watch": "typedoc --watch",
|
|
61
|
-
"docs:serve": "vite --config ./vite.docs-dev.config.mjs --host"
|
|
62
|
+
"docs:serve": "vite --config ./vite.docs-dev.config.mjs --host",
|
|
63
|
+
"publish:pre": "cp ../README.md ./README.md && cp ../LICENSE ./LICENSE && npm run dist",
|
|
64
|
+
"publish:post": "rm ./README.md && rm ./LICENSE",
|
|
65
|
+
"publish": "npm run publish:pre && npm publish --access=public && npm run publish:post"
|
|
62
66
|
},
|
|
63
67
|
"dependencies": {
|
|
64
68
|
"@pbkware/dot-net-date-number-formatting": "^0.3.0",
|