arraypress/inflector
Composer 安装命令:
composer require arraypress/inflector
包简介
A PHP library for pluralizing and singularizing English words with comprehensive irregular and uncountable word handling.
README 文档
README
A PHP library for pluralizing and singularizing English words with comprehensive irregular and uncountable word handling.
Installation
composer require arraypress/inflector
Usage
Basic Pluralization
pluralize( 'cat' ); // 'cats' pluralize( 'category' ); // 'categories' pluralize( 'child' ); // 'children' pluralize( 'person' ); // 'people' pluralize( 'analysis' ); // 'analyses'
Basic Singularization
singularize( 'cats' ); // 'cat' singularize( 'categories' ); // 'category' singularize( 'children' ); // 'child' singularize( 'people' ); // 'person' singularize( 'analyses' ); // 'analysis'
Conditional Inflection
// Returns singular when count is 1, plural otherwise inflect( 'cat', 1 ); // 'cat' inflect( 'cat', 2 ); // 'cats' inflect( 'cat', 0 ); // 'cats' // Or use the count parameter on pluralize pluralize( 'item', 1 ); // 'item' pluralize( 'item', 5 ); // 'items'
Detection
is_plural( 'cats' ); // true is_plural( 'children' ); // true is_plural( 'cat' ); // false is_singular( 'cat' ); // true is_singular( 'person' ); // true is_singular( 'people' ); // false is_uncountable( 'sheep' ); // true is_uncountable( 'information' ); // true is_uncountable( 'cat' ); // false
Case Preservation
The inflector preserves the case pattern of the original word:
pluralize( 'Cat' ); // 'Cats' pluralize( 'CAT' ); // 'CATS' pluralize( 'Person' ); // 'People' pluralize( 'PERSON' ); // 'PEOPLE' singularize( 'CHILDREN' ); // 'CHILD' singularize( 'People' ); // 'Person'
Using the Class Directly
If you prefer, you can also use the Inflector class directly:
use ArrayPress\Inflector\Inflector; Inflector::pluralize( 'category' ); // 'categories' Inflector::singularize( 'children' ); // 'child' Inflector::is_plural( 'cats' ); // true Inflector::clear_cache(); // Clear internal caches
Supported Word Types
Irregular Words
The library handles 150+ irregular English words including:
- People: person/people, man/men, woman/women, child/children
- Body parts: tooth/teeth, foot/feet, goose/geese
- Animals: mouse/mice, louse/lice, ox/oxen
- Latin/Greek: criterion/criteria, phenomenon/phenomena, analysis/analyses, thesis/theses
- Latin -us: cactus/cacti, fungus/fungi, nucleus/nuclei, radius/radii
- Latin -a: alumna/alumnae, antenna/antennae, formula/formulae
- Latin -ex/-ix: index/indices, matrix/matrices, vertex/vertices
- French: bureau/bureaux, chateau/chateaux, plateau/plateaux
- f/fe endings: leaf/leaves, life/lives, knife/knives, wolf/wolves
- Compound words: passerby/passersby, son-in-law/sons-in-law
Uncountable Words
Words that remain the same in singular and plural:
- Animals: sheep, fish, deer, moose, salmon, trout, bison
- Abstract concepts: information, advice, knowledge, news, research
- Materials: equipment, furniture, luggage, rice, water, money
- Academic fields: mathematics, physics, economics, statistics
- Other: traffic, software, feedback, homework
Regular Patterns
Standard English pluralization rules:
- Add -s: cat → cats, dog → dogs
- Add -es (s, ss, sh, ch, x, z): bus → buses, church → churches
- Change -y to -ies: city → cities, category → categories
- Change -f/-fe to -ves: leaf → leaves, knife → knives
- Add -es (consonant + o): hero → heroes, potato → potatoes
Functions
| Function | Returns | Description |
|---|---|---|
pluralize( $word, $count ) |
string |
Convert to plural (or singular if count is 1) |
singularize( $word ) |
string |
Convert to singular |
inflect( $word, $count ) |
string |
Plural if count ≠ 1, singular if count = 1 |
is_plural( $word ) |
bool |
Check if word is plural |
is_singular( $word ) |
bool |
Check if word is singular |
is_uncountable( $word ) |
bool |
Check if word is uncountable |
Performance
The library uses internal caching to optimize repeated operations. Results are cached on first use, making subsequent calls extremely fast.
// First call computes and caches pluralize( 'category' ); // Computed // Subsequent calls use cache pluralize( 'category' ); // From cache
Requirements
- PHP 8.0+
License
GPL-2.0-or-later
arraypress/inflector 适用场景与选型建议
arraypress/inflector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「inflector」 「grammar」 「english」 「singularize」 「pluralize」 「words」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arraypress/inflector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arraypress/inflector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arraypress/inflector 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
DeepL API client wrapper for Laravel
Utils Library for every day
Simple PHP Inflector
A simple library for make Lexer and Parsers to build a language
Preposition replace library
By using this standalone package, you can convert numeric values into words in English based on Bangladeshi numeric counting (lakh-crore).
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2025-11-30