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

dicset

v0.0.2

Published

A set of dictionaries (mappings)

Downloads

1

Readme

Dicset

A set of dictionaries (mappings)

Written by Vladimir Neverov [email protected] in 2014

Usage

Constructor takes path to dictionary file as first argument, settings object as second argument.

Dictionary file has an INI-like syntax:

[dicname]
from1 	to1 	comment1
from2	to2		comment2
"from 3 value"   "to 3 value"    a long and winding comment

[dicname2]
...

There are two settings recognized by now:

 - def - a default value that is returned when no dictionary is found
 - xml2js - boolean, if true - do output in xml2js style (default is old-fashioned non-compatible style :)

Lines starting with # are treated as comments and ignored. Empty lines are ignored. Columns can be divided with any number of space characters (including tabs, excluding newlines). 'from' and 'to' values can be quoted. In this case they can contain spaces. The following characters are recognized as quotes: ", ' and `

The constructor reads the file and returns an object with several lookup methods. It can throw an exception if either a dictionary file couldn't be read or is malformed (not INI-like syntax).

  • .lookup method maps values from the first column to the second one, returns object (syntax depends on xml2js option)

  • .reverse method maps values from the second column to the first one, returns object

  • .comment method maps comments to 'from' and 'to' values (returns object { from: ..., to: ... }), returns object

  • .ilookup, .ireverse and .icomment methods perform case-insensitive lookups, they return objects

  • .to_id method do a reverse lookup (by 'to' field) and return ID only ('from' field)

  • .from_id method do a straight lookup (by 'from' field) and return ID onlu

  • .to_comment and .from_comment methods do lookups by 'to' and 'from' fields respectively and return a text comment

Example:

var dic = new Dicset('/path/to/file');
console.log(dic.lookup('metro', 15));

This will lookup a 'metro' dictionary for value 15 and return an object like this (in case when xml2js option is false):

{
 	$id: 25,
 	comment: 'Central station'
}

With xml2js option set the output will be:

{
 	$: {
		id: 25
	},
 	comment: 'Central station'
}

If either dictionary is missing or a value is not found, a default value (undefined by default) is returned.

N.B.! If a lookup result (for either 'from' and 'to' lookups) is zero, this is treated as special case and undefined is returned. You can mark records that do not currently have a mapping with zero.