Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanve/yearly
Year utility to test or bump year in a string. Useful for keeping license files current.
https://github.com/ryanve/yearly
javascript opensource
Last synced: about 1 month ago
JSON representation
Year utility to test or bump year in a string. Useful for keeping license files current.
- Host: GitHub
- URL: https://github.com/ryanve/yearly
- Owner: ryanve
- License: other
- Created: 2018-01-02T01:42:42.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-07T06:02:01.000Z (almost 7 years ago)
- Last Synced: 2024-05-02T00:09:05.399Z (7 months ago)
- Topics: javascript, opensource
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/yearly
- Size: 16.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# `yearly`
Year utility to test or bump year in a string. Useful for keeping license files up to date.
```
npm install yearly
``````js
const yearly = require("yearly")
```## API
### `yearly.bump(content)`
Replace any years in `content` with the current year. Uses `yearly.express` and `yearly.full````js
yearly.bump("47") // "2018"
yearly.bump("1999 4ever") // "2018 4ever"
yearly.bump("2000 8000") // "2018 2018"
yearly.bump("Copyright (c) 1999 Mickey Mouse") // "Copyright (c) 2018 Mickey Mouse"
```### `yearly.test(content)`
Test if `content` contains current year. Uses `yearly.express` and `yearly.full````js
yearly.test("2018 4ever") // true
yearly.test("02018") // false
```### `yearly.express(year)`
Create regex for `year` string. Uses word boundary in expression```js
yearly.express("1999") // /\b1999\b/g
```### `yearly.full()`
Get the full current local year string```js
yearly.full() // "2018"
```## `node`
### `test` if license has current year
```
npm install yearly --save-dev
``````js
const yearly = require("yearly")
const assert = require("assert")
const fs = require("fs")assert.ok(
yearly.test(fs.readFileSync("LICENSE")),
"Please update LICENSE to current year: " + yearly.full()
)
```### `bump` license file
```
npm install edit-file yearly --save-dev
``````js
const editFile = require("edit-file")
const yearly = require("yearly")editFile("LICENSE", yearly.bump)
``````
git diff
```### hook into [`npm version`](https://docs.npmjs.com/cli/version) commit
```
npm install edit-file said yearly --save-dev
```Create a `yearly.js` file in your package
```js
const yearly = require("yearly")
const editFile = require("edit-file")
const said = require("said")editFile("LICENSE", yearly.bump, err => {
if (err) throw err
if (said("git diff LICENSE")) {
said("git add LICENSE")
console.log("Updated: LICENSE")
}
})
```Use [`version`](https://docs.npmjs.com/misc/scripts) script in your `package.json`
```json
"scripts": {
"version": "node yearly"
}
```## `npm test` logs bump examples
```
node test
Testing...0 => 2018
2000 => 2018
-0 => -2018
0- => 2018-
4747474747 => 2018
02018 => 2018
20182018 => 2018
2000 8000 => 2018 2018
2000.8000 => 2018.2018
2000,8000 => 2018,2018
2000-8000 => 2018-2018
B2B => B2B
9999 4EVER => 2018 4EVER
2000_8000 => 2000_8000
2000x8000 => 2000x8000
Copyright (c) 1999 Mickey Mouse => Copyright (c) 2018 Mickey Mouse
Copyright (c) 1999 Mickey Mouse => Copyright (c) 2018 Mickey Mouse
Copyright (c) 1999, Mickey Mouse => Copyright (c) 2018, Mickey MouseTests passed :)
```