Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stscoundrel/harlaw
Transform DSL files to JSON. Formatting options available for custom output.
https://github.com/stscoundrel/harlaw
dictionary dsl dsl-files javascript json lingvo nodejs utility
Last synced: 4 days ago
JSON representation
Transform DSL files to JSON. Formatting options available for custom output.
- Host: GitHub
- URL: https://github.com/stscoundrel/harlaw
- Owner: stscoundrel
- License: mit
- Created: 2020-09-18T16:13:21.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-28T18:02:50.000Z (about 1 month ago)
- Last Synced: 2024-09-28T18:07:22.618Z (about 1 month ago)
- Topics: dictionary, dsl, dsl-files, javascript, json, lingvo, nodejs, utility
- Language: TypeScript
- Homepage:
- Size: 1.48 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Harlaw
Transform DSL (Lingvo Dictionary File) files to JSON. Formatting options available for custom output.
There are many dictionaries available as .dsl, but very few in easily consumable formats. Harlaw formats the dsl files to json with decent search/replace/remove options.
Also available for [Rust](https://github.com/stscoundrel/harlaw-rs)
### Install
`npm install harlaw`
### Usage
With default settings:
```javascript
import { toJson } from 'harlaw';const input = `${__dirname}/dsl/myDictionary.dsl`
const output = `${__dirname}/json/myResult.json`await toJson(input, output);
```
By default, Harlaw performs HTML transform to Lingvo markup. For example, `[b]` becomes `` and `[i]` becomes ``.You can also pass on settings array to remove all extra markup:
```javascript
import { toJson, noMarkupSettings } from 'harlaw'const input = `${__dirname}/dsl/myDictionary.dsl`
const output = `${__dirname}/json/myResult.json`await toJson(input, output, noMarkupSettings)
```
For custom formatting needs, you can also pass on completely custom settings object:
```javascript
import { toJson } from 'harlaw';const input = `${__dirname}/dsl/myDictionary.dsl`
const output = `${__dirname}/json/myResult.json`const mySettings = {
replaces: [ // Any key & value pair you with replaced.
{ search: '[b]', replace: '' },
{ search: '[/b]', replace: '' },
{ search: '[i]', replace: '' },
{ search: '[/i]', replace: '' },
{ search: '[p]', replace: '' },
{ search: '[/p]', replace: '' },
{ search: '{-}', replace: '-' },
{ search: '[ref]', replace: '' },
{ search: '[/ref]', replace: '' },
],
removes: [ // Any elements to be replaced with ''
'\\', '[/m]', '[m1]', '[m2]', '[m3]', '[m4]', '[m5]', '[m6]', '[m7]', '[m8]', '[m9]', '[m10]', '\t', '[u]', '[/u]',
],
}await toJson(input, output, mySettings)
```
If you don't want physical json file, but would rather just do something with data, use `toArray`
```javascript
import { toArray } from 'harlaw';const input = `${__dirname}/dsl/myDictionary.dsl`
const mySettings = {
//optional
}const dictionary = await toArray(input, mySettings)
console.log(dictionary)
```
### Custom read settings.
Sometimes default settings for Node do not parse files correctly. For example, the file might be encoded in non-standard format. This might mean you need to pass custom settings for file reading.
You can use custom read options by passing readOptions object to settings. It will be passed to [createReadStream](https://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options).
```javascript
import { toJson, toArray } from 'harlaw';const input = `${__dirname}/dsl/myDictionary.dsl`
const output = `${__dirname}/json/myResult.json`const mySettings = {
replaces: { /* optional */ },
removes: { /* optional */ },
readSettings: {
encoding: 'utf16le',
// any other valid option.
},
}// Works with JSON.
await toJson(input, output, mySettings)// ...And with array.
const dictionary = await toArray(input, mySettings)console.log(dictionary)
```
#### What's in the name?
In G.R.R Martins "A Song Of Ice And Fire", there is a character named Rodrik Harlaw. He is mockingly called "The Reader". That is what my Harlaw does too; reads things no one else cares about.