kamranahmedse/php-shorthand

计算给定字符串集合的独特缩写集合。

1.0.1 2016-09-21 06:50 UTC

This package is not auto-updated.

Last update: 2024-09-14 20:04:01 UTC


README

Build Status Code Coverage Latest Stable Version

计算给定字符串集合的唯一缩写

ruby's abbrev 模块启发,允许您计算给定单词集的唯一缩写集合。

安装

使用以下命令通过 composer 安装

composer require kamranahmedse/php-shorthand

有关更详细的信息,您可以在 Packagist 上找到此包。

用法

实例化 Shorthand 类,同时传入您希望获取缩写的单词

// Introduce the class into your scope
use KamranAhmed\Shorthand\Shorthand;

$shorthand = new Shorthand([
    'crore',
    'create',
]);

$shorthands = $shorthand->generate();

它将返回一个关联数组,键设置为缩写关键字,值设置为它所指向的实际单词

// Shorthands for the above example
[
    'cre'    => 'create',
    'crea'   => 'create',
    'creat'  => 'create',
    'create' => 'create',
    'cro'    => 'crore',
    'cror'   => 'crore',
    'crore'  => 'crore',
],

使用场景

当编写命令行脚本,需要处理多个选项,并且用户可能输入选项缩写或在其他您想接受缩写的情况下,这非常有用。

例如,在一个接受选项 ['delete', 'create', 'update'] 的脚本中,它可以让您从选项中推断用户想要的内容,即使他们输入了缩写,只要它是明确的。

$ shorthand cr   # create
$ shorthand d    # delete
$ shorthand upd  # update

贡献

请随意分支、增强、提交问题、创建 pull 请求或传播信息。

许可证

MIT © Kamran Ahmed