Code Monkey home page Code Monkey logo

php-shorthand's Introduction

php-shorthand

Build Status Code Coverage Latest Stable Version

Calculate unique shorthands for a given set of strings

Inspired by ruby's abbrev module, it let's you calculate the unique set of shorthands for the given set of words.

Installation

Use the following command to install via composer

composer require kamranahmedse/php-shorthand

For further details you can find the package at Packagist.

Usage

Instantiate the Shorthand class while passing the words for which you want the shorthands

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

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

$shorthands = $shorthand->generate();

It will return an associative array with the key set to the shorthand keyword and value set to the actual word that it refers to

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

Usage Scenarios

It can come quite handy when writing command line script that takes a number of options and the user may enter the options shorthand or maybe other cases where you want to be able to accept shorthands.

For example, in a script that accepts the options ['delete', 'create', 'update'], in your script, it can let you infer from the option that user wanted even when they typed a shorthand as long as it is unambiguous

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

Contribution

Feel free to fork, enhance, open issues, create pull requests or spread the word.

License

MIT © Kamran Ahmed

php-shorthand's People

Contributors

kamranahmedse avatar peter279k avatar

Stargazers

KAZI SAYED HOSSAIN avatar Duy Truong avatar Shakir El Amrani avatar Cat  avatar Farhan avatar Captone Habiyaremye avatar  avatar FaRooQ Khan avatar Khaled Ahmed avatar Sarfraz Ahmed avatar Nabeel Ali avatar Nico Müller avatar Timothy Jacobs avatar  avatar Philipp Bräutigam avatar Jeremy Dormitzer avatar Danny Ritterman avatar BohwaZ avatar  avatar Elliot Wright avatar Attila Csaba MAROSI avatar Zeeshan Ahmad avatar Peter Ivanov avatar Adrià Pérez Gall avatar

Watchers

James Cloos avatar  avatar Peter Ivanov avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.