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

inflectrix

v1.0.2

Published

A tool to inflect words

Downloads

1

Readme

inflector

Inflector is a project that aims to generate inflections of words based on specified rules and exceptions. The rules must be specified using Regular expressions. Language data can be fed as a JSON file.

Inflector is in the early stages of development. Any contribution is welcome.

Usage

  • Clone the repository with git clone https://github.com/V-Volte/inflector
  • Install the dependencies with npm install
  • Create a file called index.js (or anything else) in the root directory of the project.

I've prepared an example file that defines a subset of the conjugation and declension rules for Latin. You can find this file as latin.json in the examplepatterns directory.

To load the Latin language from this file, all you have to do is:

const LanguageConstructor = require('./src/core/LanguageConstructor');

const latin = LanguageConstructor.constructLanguageFromJSONFile('./examplepatterns/latin.json');

Now, you can inflect any word using the inflectNoun or inflectVerb method of the Language class:

const augustus = "Augustus";
const amare = "Amāre";

console.log(latin.inflectNoun(augustus, "First Declension", "Plural", "Plural", "Genitive"));
console.log(
    latin.inflectVerb(amare, "First Conjugation", "Indicative", "Active", "Present", "Singular", "First")
);

Or, you can use the generateMarkdownInflectionTable() method of InflectionClass to generate a Markdown table of all the inflections of a word:

const fs = require('fs');
fs.writeFileSync('inflections.md', latin.getNounInflectionClass("First Declension")?.generateMarkdownInflectionTable(augustus, "Masculine"))

Defining a language

Currently, defining a new language and rules in JSON is very tedious and frankly, impossible for a normal human. Even generating this file took me about 15 minutes with Copilot automatically adding the inflection patterns in JavaScript. I'm currently working on a better way to define the rules, probably using a different JSON structure, or maybe something like YAML.

If, however, you have access to Copilot or any other AI that can generate code, you can use the addInflectionPattern function and others of its ilk to create a Language object, and save it by stringifying it into a JSON file. This is how I generated the latin.json file:

const latin = new Language(
    "Latin",
    ["Indicative", "Subjunctive", "Imperative"],
    ["Present", "Imperfect", "Future", "Perfect", "Pluperfect", "Future Perfect"],
    ["Singular", "Plural"],
    ["First", "Second", "Third"],
    ["Active", "Passive"],
    ["Masculine", "Feminine", "Neuter"],
    ["Nominative", "Genitive", "Dative", "Accusative", "Ablative", "Vocative", "Locative"]
);

const firstConjugation = new VerbInflectionClass(
    "First Conjugation",
    "(.*)(āre)",
    latin.moods,
    latin.voices,
    latin.tenses,
    latin.numbers,
    latin.persons
);

firstConjugation.addInflectionPattern(
    "Indicative",
    "Active",
    "Present",
    "Singular",
    "First",
    new InflectionPattern(firstConjugation.rootPattern, ["ō"], [1])
);

...and so on.

Contributing

If you want to contribute to this project, you can do so by creating a pull request. I'll be happy to review it and merge it if it's good. If you have any suggestions, you can create an issue.

Any contribution is welcome!