# spectral-function-past-tense

> Test Spectral values for past tense.

Latest version **1.0.7** (published 2021-12-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install spectral-function-past-tense
pnpm add spectral-function-past-tense
yarn add spectral-function-past-tense
bun add spectral-function-past-tense
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2021-12-11 |
| First published | 2021-12-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 99 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Kevin Swiber |
| Maintainers | kevinswiber |
| Keywords | openapi, asyncapi, spectral |

## Links

- npm: https://www.npmjs.com/package/spectral-function-past-tense
- Repository: https://github.com/kevinswiber/spectral-function-past-tense
- Issues: https://github.com/kevinswiber/spectral-function-past-tense/issues
- npm.io page: https://npm.io/package/spectral-function-past-tense

## Dependencies (3)

- [en-lexicon](https://npm.io/package/en-lexicon.md) ^1.0.11
- [change-case](https://npm.io/package/change-case.md) ^4.1.2
- [en-inflectors](https://npm.io/package/en-inflectors.md) ^1.0.12

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.0.7 (latest) — 2021-12-11
- 1.0.6 — 2021-12-11
- 1.0.4 — 2021-12-11
- 1.0.3 — 2021-12-11
- 1.0.2 — 2021-12-09
- 1.0.1 — 2021-12-08
- 1.0.0 — 2021-12-08

## README

# spectral-function-past-tense

A custom function for [Spectral](https://github.com/stoplightio/spectral) to check that the input contains a verb in the
past tense. This can be useful for checking the message names in an [AsyncAPI](https://www.asyncapi.com/) document.

## Installation

```
npm install spectral-function-past-tense
```

or

```
yarn add spectral-function-past-tense
```

## How it works

This custom function will attempt to parse a string of any case(snake_case, kebab-case, camelCase, etc.) and ensure it
contains a past tense verb.

## Usage

_Note: Check out the [example](https://github.com/kevinswiber/spectral-function-past-tense/tree/main/example) directory
for a complete demonstration._

A Spectral ruleset can contain custom functions. By default, with the declarative syntax, these will be in a `functions`
directory. At this time, there isn't a way to include functions from outside packages other than to wrap them in your
own function or to use the JavaScript version of a Spectral ruleset.

To wrap the `spectral-function-past-tense` custom function, create a simple Node.js module in your `functions` directory
named `past.js` with the following contents:

```js
import past from "spectral-function-past-tense";
export default past;
```

Then use the following for your Spectral YAML ruleset:

```yaml
functions: [past]
formats: [asyncapi2]
rules:
  rule:
    given: "$.channels.*.[publish,subscribe].message.name"
    then:
      function: past
```

The JavaScript version may look like this:

```js
import past from "spectral-function-past-tense";

export default {
  rules: {
    rule: {
      given: "$.channels.*.[publish,subscribe].message.name",
      then: {
        function: past,
      },
    },
  },
};
```

If the input doesn't contain a past-tense word, a validation result will be produced. Example:

```
➜ spectral lint --ruleset=./example/ruleset.yaml ./example/streetlights.yaml

./example/streetlights.yaml
 96:13  warning  rule  Value "dimLight" must be past tense.  components.messages.dimLight.name

✖ 1 problem (0 errors, 1 warning, 0 infos, 0 hints)
```

## Options

This custom function allows for optional overrides. It can either match on the entire string (e.g., `LightShining`
string will match `LightShining` override exactly) or it will match on individual words (e.g., `LightShining` string
will match `Shining` override).

In practice, with a declarative ruleset, the overrides option will look like this:

```
functions: [past]
formats: [asyncapi2]
rules:
  rule:
    given: "$.channels.*.[publish,subscribe].message.name"
    then:
      function: past
      functionOptions:
        overrides:
          - Shining
```

## License

MIT

---
_Source: https://npm.io/package/spectral-function-past-tense · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
