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

nx-properties-classifier

v1.0.0

Published

Classify property names to infer JSON data types based on singular/plural form

Readme

Property Classifier

A TypeScript package that classifies property names and infers their JSON data types based on singular/plural form detection.

Features

  • 🔍 Automatic Form Detection: Uses the pluralize library to accurately detect singular vs plural property names
  • 🎯 Smart Type Inference: Applies pattern-matching rules to infer appropriate JSON data types
  • 📋 Configurable Rules: Metadata-driven rules stored in JSON format
  • Fast & Efficient: No disk caching needed - the pluralize library is fast enough for real-time use
  • 📊 Confidence Scoring: Returns confidence levels for each classification
  • 🔧 TypeScript: Fully typed for better development experience

Installation

npm install

Quick Start

import { PropertyClassifier } from 'property-classifier';

const classifier = new PropertyClassifier();

// Classify a single property
const result = classifier.classify('users');
console.log(result);
// {
//   propertyName: 'users',
//   form: 'plural',
//   inferredType: 'array',
//   confidence: 'medium',
//   reasoning: 'Default: plural properties are arrays'
// }

// Classify multiple properties
const results = classifier.classifyBatch(['user', 'isActive', 'itemCount']);

How It Works

1. Form Detection (Singular vs Plural)

The classifier uses the pluralize npm package to determine if a property name is singular or plural:

  • user → singular
  • users → plural
  • person → singular
  • people → plural

2. Type Inference

Based on the form and pattern matching rules, the classifier infers the appropriate JSON data type:

Singular Properties

  • isActive, hasPermission, canEditboolean
  • itemCount, totalPrice, amountnumber
  • createdAt, updatedAt, timestampdate
  • name, email, titlestring
  • user, profile, dataobject

Plural Properties

  • users, items, productsarray
  • userIds, tags, categoriesarray

Special Cases

Some words have special handling defined in the rules:

  • settings, metadata, configobject (even though plural-looking)
  • news, seriesarray

API Reference

PropertyClassifier

Constructor

constructor(rulesPath?: string)

Creates a new classifier instance. Optionally provide a custom path to rules JSON file.

Methods

classify(propertyName: string): ClassificationResult

Classifies a single property name.

Returns:

{
  propertyName: string;
  form: 'singular' | 'plural';
  inferredType: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'date' | 'unknown';
  confidence: 'high' | 'medium' | 'low';
  reasoning?: string;
}
classifyBatch(propertyNames: string[]): ClassificationResult[]

Classifies multiple property names at once.

getRulesStats()

Returns statistics about the loaded rules:

{
  singularPatterns: number;
  pluralPatterns: number;
  specialCases: number;
}

Customizing Rules

Rules are stored in .metadata/parser/rules.json and consist of:

Structure

{
  "singularPatterns": [
    {
      "pattern": "^is[A-Z]",
      "inferredType": "boolean",
      "priority": 100,
      "description": "Properties starting with 'is' are typically boolean"
    }
  ],
  "pluralPatterns": [...],
  "specialCases": {
    "settings": "object",
    "metadata": "object"
  }
}

Pattern Priority

Higher priority patterns are checked first (0-100 scale):

  • 100: High confidence patterns (boolean flags, timestamps)
  • 90-95: Strong indicators (counts, IDs, money values)
  • 80-85: Common patterns (names, text fields)
  • 10: Default fallback patterns

Examples

Example 1: User Profile Schema

const classifier = new PropertyClassifier();

const properties = ['id', 'username', 'email', 'isVerified', 'followers', 'createdAt'];
const results = classifier.classifyBatch(properties);

// Generate schema
const schema = results.reduce((acc, result) => {
  acc[result.propertyName] = result.inferredType;
  return acc;
}, {});

console.log(schema);
// {
//   id: 'string',
//   username: 'string',
//   email: 'string',
//   isVerified: 'boolean',
//   followers: 'array',
//   createdAt: 'date'
// }

Example 2: E-commerce Product

const productProps = [
  'productId', 'name', 'description', 'price', 
  'inStock', 'tags', 'relatedProducts', 'reviewCount'
];

productProps.forEach(prop => {
  const result = classifier.classify(prop);
  console.log(`${prop}: ${result.inferredType} (${result.confidence})`);
});

// Output:
// productId: string (high)
// name: string (medium)
// description: string (medium)
// price: number (high)
// inStock: boolean (high)
// tags: array (medium)
// relatedProducts: array (medium)
// reviewCount: number (high)

Development

Build

npm run build

Run Examples

npm run dev

Use Cases

  • API Schema Generation: Automatically infer JSON schema from property names
  • Documentation: Generate type hints for API documentation
  • Validation: Pre-validate expected data structures
  • Code Generation: Generate TypeScript interfaces or database schemas
  • Data Migration: Understand data structure from property names

License

MIT