Naughty Program Manipulator
    Have ideas to improve npm?Join in the discussion! »

    parse-nomen
    TypeScript icon, indicating that this package has built-in type declarations

    1.3.0 • Public • Published

    parse-nomen

    A Node.js module for parsing biological names.

    Installation

    npm

    npm install parse-nomen --save

    yarn

    yarn add parse-nomen

    Usage

    JavaScript and TypeScript

    Importing

    To import in JavaScript:

    const { parseNomen } = require("parse-nomen");

    To import in TypeScript:

    import { parseNomen } from "parse-nomen";

    Example Usage

    (JavaScript or TypeScript, after importing the function)

    // Parsing
    console.log(JSON.stringify(parseNomen('Homo')));
    console.log(JSON.stringify(parseNomen('Homo sapiens')));
    console.log(JSON.stringify(parseNomen('Homo sapiens Linnaeus 1758')));
    console.log(JSON.stringify(parseNomen('Balæna maximus borealis Knox (of Hamilton not Lesson) 1838')));
    console.log(JSON.stringify(parseNomen('Homo sapiens + Praeanthropus afarensis')));
    console.log(JSON.stringify(parseNomen('Homonœa fornicata NEWMAN Edward, 1842')));
    console.log(JSON.stringify(parseNomen('Yersinia pestis (Lehmann and Neumann 1896) van Loghem, 1944')));
    console.log(JSON.stringify(parseNomen('Herpestes fuscus ssp. fuscus Waterhouse, 1838')));
    // Getting just the scientific part of the name.
    console.log(parseNomen('Herpestes fuscus ssp. fuscus Waterhouse, 1838')
      .filter(part => part.class === 'scientific')
      .map(part => part.text)
      .join(' ')
    );
    // Converting to HTML.
    console.log(parseNomen('Homo sapiens Linnaeus 1758')
      .map(part => `<span class="${part.class}">${part.text}</span>`)
      .join(' ')
    );

    Output:

    > [{"text":"Homo","class":"scientific"}]
    > [{"text":"Homo sapiens","class":"scientific"}]
    > [{"text":"Homo sapiens","class":"scientific"},{"text":"Linnaeus 1758","class":"citation"}]
    > [{"text":"Balæna maximus borealis","class":"scientific"},{"text":"Knox (of Hamilton not Lesson) 1838","class":"citation"}]
    > [{"text":"Homo sapiens","class":"scientific"},{"text":"+","class":"operator"},{"text":"Praeanthropus afarensis","class":"scientific"}]
    > [{"text":"Homonœa fornicata","class":"scientific"},{"text":"NEWMAN Edward, 1842","class":"citation"}]
    > [{"text":"Yersinia pestis","class":"scientific"},{"text":"(Lehmann and Neumann 1896) van Loghem, 1944","class":"citation"}]
    > [{"text":"Herpestes fuscus","class":"scientific"},{"text":"ssp.","class":"rank"},{"text":"fuscus","class":"scientific"},{"text":"Waterhouse, 1838","class":"citation"}]
    > Herpestes fuscus fuscus
    > <span class="scientific">Homo sapiens</span> <span class="citation">Linnaeus 1758</span>

    Testing

    yarn test

    Install

    npm i parse-nomen

    DownloadsWeekly Downloads

    2

    Version

    1.3.0

    License

    MIT

    Unpacked Size

    25.1 kB

    Total Files

    26

    Last publish

    Collaborators

    • avatar