Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oganesson

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oganesson

A parser for chemical formula strings.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Oganesson npm version Dependency Status

A parser for chemical formula strings.

API

// ES6
import { tokenize, countElements, getMass } from 'oganesson';

tokenize(<formula>)

// ES5
const oganesson = require('oganesson');

oganesson.tokenize(<formula>)

tokenize(formula)

Tokenizes the given formula.

Arguments
  • formula (String): The chemical formula to tokenize.

    Note: The formula does not necessarily have to be valid.

Returns

An object with an array of tokens.

Examples
Valid formula
tokenize('Ba(NO3)2');
[
  {
    "type": "element",
    "value": "Ba"
  },
  {
    "type": "parenthesis",
    "value": "open"
  },
  {
    "type": "element",
    "value": "N"
  },
  {
    "type": "element",
    "value": "O"
  },
  {
    "type": "subscript",
    "value": 3
  },
  {
    "type": "parenthesis",
    "value": "close"
  },
  {
    "type": "subscript",
    "value": 2
  }
]
Invalid, but parseable formula
tokenize('B)(')
[
  {
    "type": "element",
    "value": "B"
  },
  {
    "type": "parenthesis",
    "value": "close"
  },
  {
    "type": "parenthesis",
    "value": "open"
  }
]
Unparseable formula
tokenize('aB)(')
// Throws an error

countElements(tokens)

Counts the number of each element in the given tokens.

Arguments
  • tokens (Array): An array of tokens

    Note: The tokens should be in the format that tokenize returns.

Returns

An object with each element mapped to the number of instances it occurs in the tokenization.

Examples
countElements(tokenize('Ba(NO3)2');
{
  "Ba": 1,
  "N": 2,
  "O": 6
}

getMass(counts)

Gets the total mass of the given counts.

Arguments
  • counts (Object): The counts of each element.

    Note: The counts should be in the format that countElements returns.

Returns

The total mass of the given counts.

Examples
getMass(countElements(tokenize('Ba(NO3)2')));
261.33

Todo

  • Throw an error in either tokenize or countElements when the formula is invalid.

FAQs

Package last updated on 08 Jan 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc