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 5, 2021
1 parent 5b7f847 commit c164e7c
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 30 deletions.
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
node-version:
- 14
- 12
- 10
- 8
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
6 changes: 2 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ Generate a unique random string.
@example
```
import uniqueString = require('unique-string');
import uniqueString from 'unique-string';
uniqueString();
//=> 'b4de2a49c8ffa3fbee04446f045483b2'
```
*/
declare function uniqueString(): string;

export = uniqueString;
export default function uniqueString(): string;
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const cryptoRandomString = require('crypto-random-string');
import cryptoRandomString from 'crypto-random-string';

module.exports = () => cryptoRandomString(32);
export default function uniqueString() {
return cryptoRandomString({length: 32});
}
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectType} from 'tsd';
import uniqueString = require('.');
import uniqueString from './index.js';

expectType<string>(uniqueString());
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": "Generate a unique random string",
"license": "MIT",
"repository": "sindresorhus/unique-string",
"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 @@ -30,11 +33,11 @@
"hex"
],
"dependencies": {
"crypto-random-string": "^2.0.0"
"crypto-random-string": "^4.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
10 changes: 1 addition & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,23 @@

> Generate a unique random string

## Install

```
$ npm install unique-string
```


## Usage

```js
const uniqueString = require('unique-string');
import uniqueString from 'unique-string';

uniqueString();
//=> 'b4de2a49c8ffa3fbee04446f045483b2'
```


## API

### uniqueString()

Returns a 32 character unique string. Matches the length of MD5, which is [unique enough](https://stackoverflow.com/a/2444336/64949) for non-crypto purposes.


## 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 uniqueString from '.';
import uniqueString from './index.js';

test('main', t => {
t.is(uniqueString().length, 32);
Expand Down

0 comments on commit c164e7c

Please sign in to comment.