npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

harlaw

v1.1.12

Published

Transform DSL (Lingvo Dictionary File) files to JSON. Formatting options available for custom output.

Downloads

114

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

Install

npm install harlaw

Usage

With default settings:

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 <strong/> and [i] becomes <i>.

You can also pass on settings array to remove all extra markup:

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:

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: '<strong>' },
    { search: '[/b]', replace: '</strong>' },
    { search: '[i]', replace: '<i>' },
    { search: '[/i]', replace: '</i>' },
    { search: '[p]', replace: '<span>' },
    { search: '[/p]', replace: '</span>' },
    { search: '{-}', replace: '-' },
    { search: '[ref]', replace: '<span class="reference">' },
    { search: '[/ref]', replace: '</span>' },
  ],
  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

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.

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.