New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

parse-nomen

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-nomen

TypeScript/JavaScript function for parsing biological names.

latest
Source
npmnpm
Version
2.1.3
Version published
Maintainers
1
Created
Source

parse-nomen

A Node.js module for parsing biological names.

Installation

npm

npm install parse-nomen --save

yarn

yarn add parse-nomen

Usage

Importing

To import in JavaScript:

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

To import in TypeScript:

import { parseNomen, NOMEN_PART_CLASSES } from "parse-nomen"
import type { NomenPart, NomenPartClass } from "parse-nomen"

Example Usage

(JavaScript or TypeScript, after importing the function)

// List all nomen part classes.
console.log(JSON.stringify(NOMEN_PART_CLASSES))
// 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:

> ["citation","comment","operator","rank","scientific","vernacular"]
> [{"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

Keywords

binomial

FAQs

Package last updated on 19 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts