indefinite:根据名词是否以元音开头,在名词前加上不定冠词-a或an-

  • S8_974758
    了解作者
  • 142.4KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-20 05:52
    上传日期
不定 根据名词是否以元音开头,在名词前加上不定冠词-或-。 安装 npm install --save indefinite 概括 检查名词是否以元音开头并决定是否以“ a”或“ an”作为前缀并不难,但我每次都对手动进行此操作感到厌倦。 所以现在有这个。 只需传递单词,并且indefinite将返回以单词“ a”或“ an”为前缀的单词,具体取决于单词的第一个字母。 从2.0.0版开始, indefinite将尝试检测何时传入首字母缩写词,并以不同的方式对待响应。 例如,由于我们读长U的方式,它应该是“ UFO”而不是“ UFO”。这不是一门完美的科学,因此您可能会有误报。 从2.0.2版开始, indefinite还将查阅不规则单词的列表以确定适当的文章。 例如,应为“一个小时”而不是“一个小时”。 它还尝试使用各种形式的单词(检查单数,复数甚至是过去时态,因为过去时态动词可以用
indefinite-master.zip
  • indefinite-master
  • dist
  • indefinite.min.js
    3.7KB
  • indefinite.js
    12.1KB
  • gulp
  • open.js
    180B
  • codeclimate.js
    348B
  • karma.js
    382B
  • watch.js
    167B
  • spawn.js
    323B
  • config.js
    153B
  • clean.js
    188B
  • lint.js
    319B
  • test
  • indefinite.js
    9.7KB
  • lib
  • rules
  • numbers.js
    1006B
  • acronyms.js
    1KB
  • other.js
    1.2KB
  • helpers.js
    478B
  • rules.js
    110B
  • indefinite.js
    762B
  • irregular-words.js
    2.8KB
  • webpack.config.js
    707B
  • CONTRIBUTING.md
    3.6KB
  • README.md
    5.3KB
  • gulpfile.js
    457B
  • .codeclimate.yml
    341B
  • karma.conf.js
    936B
  • .gitignore
    66B
  • .eslint.json
    2.2KB
  • package.json
    1.8KB
  • .babelrc
    63B
  • .travis.yml
    286B
  • LICENSE
    1.1KB
  • package-lock.json
    484.1KB
内容介绍
[![Build Status](https://travis-ci.org/tandrewnichols/indefinite.png)](https://travis-ci.org/tandrewnichols/indefinite) [![downloads](http://img.shields.io/npm/dm/indefinite.svg)](https://npmjs.org/package/indefinite) [![npm](http://img.shields.io/npm/v/indefinite.svg)](https://npmjs.org/package/indefinite) [![Code Climate](https://codeclimate.com/github/tandrewnichols/indefinite/badges/gpa.svg)](https://codeclimate.com/github/tandrewnichols/indefinite) [![Test Coverage](https://codeclimate.com/github/tandrewnichols/indefinite/badges/coverage.svg)](https://codeclimate.com/github/tandrewnichols/indefinite) [![dependencies](https://david-dm.org/tandrewnichols/indefinite.png)](https://david-dm.org/tandrewnichols/indefinite) ![Size](https://img.shields.io/badge/size-2kb-brightgreen.svg) # indefinite Prefix a noun with an indefinite article - a or an - based on whether it begins with a vowel. ## Installation `npm install --save indefinite` ## Summary It's not hard to check whether a noun begins with a vowel and decide whether to prefix with "a" or "an," but I got tired of doing it manually every time. So now there's this. Just pass in the word, and `indefinite` will return the word prefixed with either "a " or "an " depending on the first letter of the word. As of version 2.0.0, `indefinite` will attempt to detect when an acronym is passed in and treat the response differently. E.g. it should be "a UFO" not "an UFO" because of how we pronounce a long U. This isn't a perfect science, so you might have false positives. As of version 2.0.2, `indefinite` will also consult a list of irregular words to determine the appropriate article. For example, it should be "an hour" not "a hour." It also _attempts_ to do this with various forms of the words (checking for singular, plural, and even past tense, since past tense verbs can be used as adjectives, as in "an honored man"). This is not an exact science either, and the list of irregulars is not exhaustive (and probably won't ever be), but if you find a word that's not in the list that's returning the wrong thing, please open an issue so it can be corrected. ## Usage ```js var a = require('indefinite'); console.log(a('apple')); // "an apple" console.log(a('banana')); // "a banana" console.log(a('UFO')); // 'a UFO' console.log(a('hour')); // 'an hour' console.log(a('ukelele')); // 'a ukelele' ``` Indefinite also accepts an options object as the second parameter. The following options are supported: - `articleOnly` - Return only the article. - `capitalize` - Capitalize the article. - `caseInsensitive` - Ignore the casing of the word passed in (i.e. bypassing the acronym checking). This is useful if, for some reason, you're yelling on the internet and want to make sure "UGLY GARDEN GNOME" doesn't become "a UGLY GARDEN GNOME." - `numbers` - When numbers are passed in, they are prefixed with "a" except for 8, 11, 18, and higher numbers starting with 8. _However_, numbers like 1100 are ambiguous. Should it be "a one thousand one hundred" or "an eleven hundred"? There's not really any programmatic way to know this for sure, but if _you_ know for sure, you can use the `numbers` option to tell `indefinite` how to handle these cases. The default is "formal" in which numbers are read literally (the way you'd say them if they were written out), but if you pass `numbers: 'colloquial'`, the "eleven hundred"/"eighteen hundred" readings will be used. ```js console.log(a('apple', { articleOnly: true })); // 'an' console.log(a('banana', { articleOnly: true })); // 'a' console.log(a('apple', { capitalize: true })); // 'An apple' console.log(a('banana', { capitalize: true })); // 'A banana' console.log(a('UGLY SWEATER', { caseInsensitive: true })); // 'an UGLY SWEATER' console.log(a('2')); // 'a 2' console.log(a('8')); // 'an 8' console.log(a('1892')); // 'a 1892' -> read "a one thousand eight hundred ninety-two" console.log(a('1892', { numbers: 'colloquial' })); // 'an 1892' -> read "an eighteen ninety-two" ``` ### Browser Files in `dist` are UMD format, and `package.json` contains a `browser` field pointing to `dist/indefinite.js`, so you should be able to bundle this via webpack, rollup, browserify, etc. or serve it in ye olde javascript fashion and access it via window. ## Detecting the need for an indefinite article It's worth mentioning that `indefintite` currently only differentiates between `a` and `an` for you. It doesn't do anything to decide if an indefinite article is required, so if you pass a plural to `indefinite`, you'll get something like "a shoes" back, which is obviously wrong. You can look at [this issue](https://github.com/tandrewnichols/indefinite/issues/23) for more context on why this isn't supported at the moment. It _could_ be in the future, but there are some prohibitive issues to work through first. For now, it is up to you (the consumer) to either call or not call `indefinite` depending on the plurality of the word. You can do something like the suggestion in that issue: ```javascript const indefinite = require('indefinite'); const pluralize = require('pluralize'); module.exports = (subject) => { if (pluralize(subject) === subject) { return subject; } return indefinite(subject); }; ``` Or you can try [is-singular](https://www.npmjs.com/package/is-singular) or [is-plural](https://www.npmjs.com/package/is-plural). ## Contributing Please see [the contribution guidelines](contributing.md).
评论
    相关推荐
    • npm
      npm install 编译和热重装以进行开发 npm run serve 编译并最小化生产 npm run build 运行测试 npm run test 整理和修复文件 npm run lint 运行单元测试 npm run test:unit 自定义配置 请参阅。
    • npm-utils:异步NPM Shell命令
      npm-utils 异步NPM Shell命令:安装,测试等。 用 var npmUtils = require ( 'npm-utils' ) ; npmUtils . version ( ) . then ( function ( semver ) { console . log ( 'NPM version %s' , semver ) ; } ) ; ...
    • npm-max:NPM软件包
      最大NPM 该函数返回最大值 npm install
    • npmTest:测试npm
      npmTest 测试npm
    • npm-lifecycle:npm生命周期脚本运行器
      npm v7发布后,将不建议使用此模块。 请不要绝对依赖它。 npm v7中使用的生命周期脚本运行程序是 。 请继续使用该模块。 npm-lifecycle 是一个独立的库,用于执行软件包的生命周期脚本。 它是从npm本身提取的,...
    • npm-fzf:使用fzf模糊搜索npm模块
      npm-fzf ,短名为npf ,提供了一些最常用的命令故宫模糊搜索 ,即npm ls , npm search , npm run ,创造一个更充实的发展与经验npm 。 要求 必须: npf需要运行时或更高版本的节点8。 强烈推荐: 被大量使用npf ...
    • npmd-install
      npmd 安装 从 npmd-resolve 树安装节点模块。 npm install - g npmd - resolve npmd - install npmd - resolve browserify | npmd - install 另外, 一个关键部分 执照 麻省理工学院
    • npm-cli-login
      npm-cli-login 允许您不使用STDIN,STDOUT登录到NPM。 在CI构建系统等地方使用。 还可以在〜/ .npmrc文件中创建/修改条目以进行身份​​验证。 安装 npm install -g npm-cli-login 使用-g标志通过CLI使用npm-cli-...
    • npm-install-missing:一个NPM模块,用于重新安装缺少的依赖项
      npm-install-missing 一个NPM模块,用于重新安装缺少的依赖项。 在处理由于缺少模块依赖性而导致部署失败的项目后,我创建了此模块。 npm install会由于未知原因且没有错误而无法安装所需的依赖项。 由于npm ...
    • npmexclude:从 npm install 和 npm update 中排除模块
      我制作这个工具是因为我假设npm install和npm update如果其中一个模块失败,则不会安装任何模块。 这个假设是不正确的; 显然我没有给予足够的重视。 我想如果您想抑制错误消息,这个工具仍然很有用,但重定向 ...