__ __ __ _
/ /__ ____ ____ / /_ _____ ____ _ _____ / /_ (_) ____ ____ _____
/ //_/ / __ \ / __ \ / __/ / ___/ / __ `/ / ___/ / __/ / / / __ \ / __ \ / ___/
/ ,< / /_/ / / / / // /_ / / / /_/ / / /__ / /_ / / / /_/ / / / / / (__ )
/_/|_| \____/ /_/ /_/ \__/ /_/ \__,_/ \___/ \__/ /_/ \____/ /_/ /_/ /____/
npm i --save kontractions
or yarn add kontractions
import kontractions from 'kontractions'
const kontractions = require('kontractions')
kontractions.contract(string)
: Converts a string containing longforms to a string containing contractions.kontractions.expand(string)
: Converts a string containing contractions to a string containing longforms, or the various possible longforms.kontractions.expandToList(string)
: Converts a string containing contractions to a list of strings containing all possible longforms.kontractions.updateContractions(object)
: Accepts an object and can be used for extending, modifying, or disabling the built-in default contractions.kontractions.updateLongforms(object)
: Accepts an object and can be used for extending, modifying, or disabling the built-in default longforms.
kontractions.contract("I did not do it.")
//=> i didn't do it.kontractions.expand("I didn't do it.")
//=> i did not do it.kontractions.expand("I hope there's more food.")
//=> i hope (( there has || there is )) more food.kontractions.expandToList("I didn't do it.")
//=> [ 'i did not do it.' ]kontractions.expandToList("I hope there's more food.")
//=> [ 'i hope there has more food.', 'i hope there is more food.' ]kontractions.updateContractions({"they'd've": ['they would have']})
//=> The contraction they'd've will now be recognized when using thecontract
method.kontractions.updateLongforms({"they would have": "they'd've"})
//=> The longform they would have will now be recognized when using theexpand
method.kontractions.updateContractions({"they'd've": ['they would have']})
//=> Pass a falsy value to disable a contraction.kontractions.updateLongforms({"they would have": false})
//=> Pass a falsy value to disable a longform.
This library aims to do one thing and do it well. With regards to the expand
method, while it would be possible to examine the context in which contractions are used to determine the proper expansion, that will likely remain beyond the scope of this package. Therefore, consumers will need to implement their own logic to examine the output and pick the correct expansion.
All contributors will receive proper attribution, as outlined in the awesome All-Contributors specification developed by open-source superstar Kent C. Dodds.
This project was bootstrapped with Babel Starter Kit. To get started with development, fork this repo and make edits to the src
directory. Install dependencies with npm install
or yarn
. Run tests with npm test
.
kontractions is available under MIT. See LICENSE for more details.
- Add option to enable 3-word+ contractions