Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 28, 2021
1 parent ec2c49a commit c311e65
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 30 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
- 8
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
6 changes: 2 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Truncate a semver version: `1.2.3` → `1.2.0`.
@example
```
import semverTruncate = require('semver-truncate');
import semverTruncate from 'semver-truncate';
semverTruncate('1.2.3-foo', 'patch');
//=> '1.2.3'
Expand All @@ -18,6 +18,4 @@ semverTruncate('1.2.3', 'major');
//=> '1.0.0'
```
*/
declare function semverTruncate(version: string, type: 'patch' | 'minor' | 'major'): string;

export = semverTruncate;
export default function semverTruncate(version: string, type: 'patch' | 'minor' | 'major'): string;
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const semver = require('semver');
import semver from 'semver';

module.exports = (version, type) => {
export default function semverTruncate(version, type) {
if (!['major', 'minor', 'patch'].includes(type)) {
throw new TypeError(`Invalid version type: ${version}`);
}
Expand All @@ -25,4 +24,4 @@ module.exports = (version, type) => {
}

return version.format();
};
}
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import semverTruncate = require('.');
import semverTruncate from './index.js';

expectType<string>(semverTruncate('1.2.3-foo', 'patch'));
expectType<string>(semverTruncate('1.2.3', 'minor'));
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"description": "Truncate a semver version: `1.2.3` → `1.2.0`",
"license": "MIT",
"repository": "sindresorhus/semver-truncate",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -28,11 +31,11 @@
"simplify"
],
"dependencies": {
"semver": "^6.0.0"
"semver": "^7.3.5"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.39.1"
}
}
11 changes: 1 addition & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

> Truncate a semver version: `1.2.3``1.2.0`

## Install

```
$ npm install semver-truncate
```


## Usage

```js
const semverTruncate = require('semver-truncate');
import semverTruncate from 'semver-truncate';

semverTruncate('1.2.3-foo', 'patch');
//=> '1.2.3'
Expand All @@ -25,7 +23,6 @@ semverTruncate('1.2.3', 'major');
//=> '1.0.0'
```


## API

### truncateSemver(version, type)
Expand All @@ -42,15 +39,9 @@ Type: `'patch' | 'minor' | 'major'`

Version type to truncate to.


## Related

- [latest-semver](https://github.com/sindresorhus/latest-semver) - Get the latest stable semver version from an array of versions
- [to-semver](https://github.com/sindresorhus/to-semver) - Get an array of valid, sorted, and cleaned semver versions from an array of strings
- [semver-regex](https://github.com/sindresorhus/semver-regex) - Regular expression for matching semver versions
- [semver-diff](https://github.com/sindresorhus/semver-diff) - Get the diff type of two semver versions: `0.0.1` `0.0.2``patch`


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import semverTruncate from '.';
import semverTruncate from './index.js';

test('main', t => {
t.is(semverTruncate('1.2.3-foo', 'patch'), '1.2.3');
Expand Down

0 comments on commit c311e65

Please sign in to comment.