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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@recipe-scope/quantity-parser

v0.1.0

Published

Zero-dependency Japanese quantity string parser for recipe ingredients

Downloads

387

Readme

@recipe-scope/quantity-parser

Zero-dependency Japanese quantity string parser for recipe ingredients.

Installation

npm install @recipe-scope/quantity-parser

Usage

Basic Parsing

import { QuantityParser } from '@recipe-scope/quantity-parser';

// Simple quantities
QuantityParser.parse('100g');      // { value: 100, unit: 'g' }
QuantityParser.parse('大さじ1');    // { value: 1, unit: '大さじ' }
QuantityParser.parse('1/2カップ');  // { value: 0.5, unit: 'カップ' }

// Full-width numbers
QuantityParser.parse('3個');       // { value: 3, unit: '個' }

// Fractions
QuantityParser.parse('1と1/2カップ'); // { value: 1.5, unit: 'カップ' }
QuantityParser.parse('半個');        // { value: 0.5, unit: '個' }

// Ranges (uses minimum value)
QuantityParser.parse('1~2本');      // { value: 1, unit: '本' }

// Parentheses (extracts grams/ml)
QuantityParser.parse('なす(100g)'); // { value: 100, unit: 'g' }

// Tube measurements
QuantityParser.parse('チューブ3cm'); // { value: 3, unit: 'チューブcm' }

Formatting

import { QuantityFormatter } from '@recipe-scope/quantity-parser';

// Basic formatting
QuantityFormatter.format(100, 'g');    // '100 g'
QuantityFormatter.format(2, '個');      // '2 個'

// Spoon fractions
QuantityFormatter.format(1.5, '大さじ'); // '大さじ 1と1/2'
QuantityFormatter.format(0.5, '小さじ'); // '小さじ 1/2'

// Tube measurements
QuantityFormatter.format(3, 'チューブcm'); // 'チューブ3cm'

// Size prefixes
QuantityFormatter.format(2, '小個');    // '小2個'

// Ambiguous units
QuantityFormatter.format(0, '少々');    // '少々'
QuantityFormatter.format(0, '適量');    // '適量'

Configuration

Access unit configuration for custom calculations:

import { UNITS_CONFIG } from '@recipe-scope/quantity-parser';

// Standard volumes in ml
UNITS_CONFIG.STANDARD_VOLUME_ML['大さじ']; // 15
UNITS_CONFIG.STANDARD_VOLUME_ML['小さじ']; // 5
UNITS_CONFIG.STANDARD_VOLUME_ML['カップ']; // 200

// Countable unit aliases
UNITS_CONFIG.UNIT_SINGLE_ALIASES; // ['個', '本', '匹', '尾', '玉', '粒', '株']

// Ambiguous units
UNITS_CONFIG.AMBIGUOUS; // ['少々', '適量', 'ひとつまみ', '適宜', 'ひとつかみ']

Features

  • Zero dependencies - Pure TypeScript implementation
  • Full-width support - Handles both half-width and full-width numbers
  • Fraction parsing - Supports various fraction formats (1/2, 半, 1と1/2, 8分の1)
  • Range handling - Extracts minimum value from ranges (1~2個 → 1)
  • Parentheses extraction - Prioritizes gram/ml values in parentheses
  • Unit normalization - Normalizes units (cc → ml, コ → 個)
  • Preprocessing - Removes cutting instructions (みじん切り, 乱切り, etc.)

License

MIT