CommunityWriting & Editinggithub.com

unit-converter

Convert e-commerce/logistics specification units (kg·cm·V·W): parse and convert text with units like "5kg 30cm" into standardized units. Ideal for e-commerce operations, logistics pricing, and BOM organization.

What is unit-converter?

This skill provides pure functions (Node ESM, zero dependencies) for parsing text values with units and converting them to standardized units. It is designed for developers working with e-commerce, logistics, and BOM data who need to normalize weight (to kg), dimensions (to cm), voltage (to V), power (to W), color temperature (to K), and luminous flux (to lm). The module extracts from a production parser used in an Electron collector app, and is fully local with no network calls. It returns null on parsing failure instead of throwing errors, allowing callers to handle defaults gracefully. Supported platforms include any Node.js environment (ESM) and can be imported directly into scripts or applications.

Works with~Claude Code~Codex CLI~Cursor
npx skills add shuangying0001-beep/unit-converter

Installed? Explore more Writing & Editing skills: steipete/notion, langchain-ai/langchain, bytedance/podcast-generation · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

unit-converter —— Unit Conversion / Specification Structuring

Parse text values with units into standardized unit values. Pure functions (Node ESM, zero dependencies), directly importable. Extracted from caijiqi-kaifa/electron/collector/content-parser.ts's parseWeightToKg / parseDimensionsToCm, and extended with voltage/power/color temperature/lumen.

Use Cases

  • Amazon / e-commerce platform scraped weight and dimension values in pounds / inches / oz, need to unify to kg / cm
  • Product spec text (e.g., Weight: 2.5 kg, Dimensions: 10 x 8 x 2 inches, Voltage: 120V) needs to be structured for database storage
  • Logistics pricing based on weight, supply chain dimension database normalization before storing

Usage

import { parseWeightToKg, parseDimensionsToCm, parseVoltageToV, parseSpec } from './scripts/unit-converter.mjs';

parseWeightToKg('15.4 pounds');          // 6.984 (kg)
parseWeightToKg('500 g');                // 0.5
parseDimensionsToCm('10 x 8 x 2 inches');// { length: 25.4, width: 20.32, height: 5.08 }
parseDimensionsToCm('300x200x100 mm');   // { length: 30, width: 20, height: 10 }
parseVoltageToV('120 volts');            // 120
parseSpec('Weight: 1.2kg, Dimensions: 10x8x2in, Voltage 120V 60W'); // auto extract key parameters

Core API

  • parseWeightToKg(value) → number | null: Supports kg / pounds(lbs) / ounces(oz) / grams(g) → kg (rounded to 3 decimal places)
  • parseDimensionsToCm(value) → { length?, width?, height? } | null: Supports L x W x H (inches|in|cm|mm) → cm (rounded to 2 decimal places, defaults to inches if unit missing)
  • parseVoltageToV(value) → number | null: V / volts
  • parseWattageToW(value) → number | null: W / watts
  • parseColorTempToK(value) → number | null: K / kelvin
  • parseLumens(value) → number | null: lm / lumens
  • parseSpec(text) → Batch extract all recognizable parameters from a text string (returns object)

Notes

  • Returns null on parsing failure (no throwing), caller decides default values.
  • Fully local parsing, no network calls, no data upload.

Related Skills