Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ai/nanoid
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.3.4
Choose a base ref
...
head repository: ai/nanoid
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4.0.0
Choose a head ref
  • 9 commits
  • 25 files changed
  • 2 contributors

Commits on May 4, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    williamdes William Desportes
    Copy the full SHA
    21728dc View commit details

Commits on Jun 7, 2022

  1. Update dependencies

    ai committed Jun 7, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    williamdes William Desportes
    Copy the full SHA
    9a967ea View commit details
  2. Remove Node.js 10 and 12 support

    ai committed Jun 7, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    williamdes William Desportes
    Copy the full SHA
    77c05f0 View commit details
  3. Remove CJS support

    ai committed Jun 7, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4f55442 View commit details
  4. Update clean-publish

    ai committed Jun 7, 2022
    Copy the full SHA
    b8a5e61 View commit details
  5. Clean up docs

    ai committed Jun 7, 2022
    Copy the full SHA
    96f5d56 View commit details
  6. Move benchmark to ESM

    ai committed Jun 7, 2022
    Copy the full SHA
    951dbbb View commit details

Commits on Jun 8, 2022

  1. Update dependencies

    ai committed Jun 8, 2022
    Copy the full SHA
    3046c10 View commit details
  2. Release 4.0 version

    ai committed Jun 8, 2022
    Copy the full SHA
    fd80ce3 View commit details
27 changes: 0 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -52,33 +52,6 @@ jobs:
run: pnpm unit
env:
FORCE_COLOR: 2
old:
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 12
- 10
name: Node.js ${{ matrix.node-version }} Quick
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v1
with:
version: 3
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Run unit tests
run: pnpm unit
env:
FORCE_COLOR: 2
benchmark:
name: Benchmark
runs-on: ubuntu-latest
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).

## 4.0
* Removed CommonJS support. Nano ID 4 will work only with ESM applications.
We will support 3.x branch with CommonJS for users who can’t migrate to ESM.
* Removed Node.js 10 and Node.js 12 support.
* Reduced npm package size.

## 3.3.4
* Fixed `--help` in CLI (by @Lete114).

60 changes: 14 additions & 46 deletions README.id-ID.md
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ Mendukung penjelajah (browser) modern, IE [dengan Babel](https://developer.epage
alt="Disponsori oleh Evil Martians" width="236" height="54">
</a>


## Table of Contents

- [Perbandingan dengan UUID](#perbandingan-dengan-uuid)
@@ -42,17 +43,15 @@ Mendukung penjelajah (browser) modern, IE [dengan Babel](https://developer.epage
- [Alfabet dan Ukuran (Custom)](#alfabet-dan-ukuran-penyesuaian)
- [Generasi Random Bytes (Custom)](#generasi-random-bytes-custom)
- [Penggunaan](#penggunaan)
- [IE](#ie)
- [React](#react)
- [React Native](#react-native)
- [Rollup](#rollup)
- [PouchDB dan CouchDB](#pouchdb-dan-couchdb)
- [Mongoose](#mongoose)
- [Web Workers](#web-workers)
- [CLI](#cli)
- [Bahasa Pemrograman Lainnya](#bahasa-pemrograman-lainnya)
- [Alat](#alat)


## Perbandingan dengan UUID

Nano ID dapat dibandingkan dengan UUID v4 (yang berbasis acak / _randomly generated_). Nano ID dan UUID v4 memiliki jumlah bita yang mirip pada ID yang dihasilkan (126 bita pada NanoID dan 122 bita pada UUID), karenanya ia memiliki probabilitas _collision_ (konflik / tabrakan) yang hampir serupa:
@@ -65,6 +64,7 @@ Ada tiga buah perbedaan antara Nano ID dan UUID v4:
2. Kode sumber Nano ID **empat kali lebih kecil** ketimbang `uuid/v4`: 130 bytes dibanding 483 bytes.
3. Karena menggunakan trik alokasi memori, Nano ID **dua kali lebih cepat** ketimbang UUID.


## Benchmark

```rust
@@ -95,6 +95,7 @@ rndm 2,674,806 ops/sec

Konfigurasi pengujian: ThinkPad X1 Carbon Gen 9, Fedora 34, Node.js 16.10.


## Keamanan

_Lihat artikel yang informatif tentang teori angka acak: [Nilai acak yang aman dalam Node.js (English)](https://gist.github.com/joepie91/7105003c3b26e65efcea63f3db82dfba)_.
@@ -110,6 +111,7 @@ _Lihat artikel yang informatif tentang teori angka acak: [Nilai acak yang aman d

- **Kerentanan.** Untuk melaporkan sebuah _security vulnerability_ atau kerentanan, mohon menggunakan [Tidelift Security Contact](https://tidelift.com/security). Tidelift akan mengkoordinasikan pembetulan dan penyingkapan dari kerentanan tersebut.


## Instalasi

```bash
@@ -128,18 +130,14 @@ Nano ID tersedia dalam bentuk ES modules. Tidak perlu melakukan konfigurasi apap
import { nanoid } from 'nanoid'
```

Dalam Node.js, dapat digunakan gaya _import_ ala CommonJS:

```js
const { nanoid } = require('nanoid')
```

## API

Nano ID memiliki tiga buah API: normal (_blocking_), asinkronus (_asynchronous_), dan _non-secure_.

Bawaannya, Nano ID menggunakan simbol yang _URL-friendly_ (`A-Za-z0-9_-`) dan mengembalikan ID dengan 21 karakter (untuk memiliki probabilitas collision / tabrakan yang mirip dengan UUID v4).


### Blocking

Penggunaan Nano ID yang aman dan yang paling mudah.
@@ -161,6 +159,7 @@ Jangan lupa memeriksa tingkat keamanan dari ukuran ID dalam situs [ID collision

Dapat digunakan pula [custom alphabet](#custom-alphabet-or-size) atau [random generator](#custom-random-bytes-generator) yang lain.


### Async

Untuk menghasilkan bytes yang acak dan aman secara kriptografis, CPU mengumpulkan noise elektromagnetik. Umumnya, entropi sudah dikumpulkan terlebih dahulu.
@@ -181,6 +180,7 @@ Referensi lebih lanjut tentang entropi dapat dilihat pada dokumentasi fungsi [`c

Sayangnya, keuntungan Web Crypto API akan hilang di browser apabila menggunakan API asinkronus ini. Untuk sekarang, browser dibatasi hanya menggunakan API sinkronus (untuk keamanan) atau API asinkronus (lebih cepat, tetapi karena keuntungan Web Crypto hilang, keamanannya sedikit lebih rendah ketimbang penggunaan API sinkronus).


### Non-Secure

Konfigurasi bawaan Nano ID menggunakan random bytes generator yang berasal dari perangkat keras untuk keamanan dan probabilitas collision yang rendah. Apabila tidak terlalu memikirkan soal keamanan, dapat pula menggunakan non-secure generator yang lebih cepat.
@@ -190,6 +190,7 @@ import { nanoid } from 'nanoid/non-secure'
const id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqLJ"
```


### Alfabet dan Ukuran (Custom)

`customAlphabet` digunakan untuk membuat Nano ID dengan alfabet dan ukuran ID yang sesuai dengan kebutuhan (dapat dikustomisasi).
@@ -220,6 +221,7 @@ const nanoid = customAlphabet('1234567890abcdef', 10)
user.id = nanoid()
```


### Generasi Random Bytes (Custom)

`customRandom` digunakan untuk membuat Nano ID yang mengganti alfabet dan algoritma _random bytes generator_ yang telah diimplementasikan pada versi bawaan (dalam artian menggunakan algoritma sendiri untuk mendapatkan random bytes).
@@ -248,23 +250,8 @@ const nanoid = customRandom(urlAlphabet, 10, random)

API asinkronus dan non-secure tidak tersedia untuk fungsi `customRandom`.

## Penggunaan

### IE

Apabila mengimplementasikan di Internet Explorer, dibutuhkan untuk melakukan [transpile pada `node_modules`](https://developer.epages.com/blog/coding/how-to-transpile-node-modules-with-babel-and-webpack-in-a-monorepo/) dengan Babel dan menambahkan alias untuk `crypto` seperti berikut:

```js
// polyfills.js
if (!window.crypto) {
window.crypto = window.msCrypto
}
```

```js
import './polyfills.js'
import { nanoid } from 'nanoid'
```
## Penggunaan

### React

@@ -311,18 +298,6 @@ import 'react-native-get-random-values'
import { nanoid } from 'nanoid'
```

### Rollup

Untuk Rollup, dibutuhkan [`@rollup/plugin-node-resolve`](https://github.com/rollup/plugins/tree/master/packages/node-resolve) untuk versi browser.

```js
plugins: [
nodeResolve({
browser: true
})
]
```

### PouchDB dan CouchDB

Dalam PouchDB dan CouchDB, ID tidak bisa dimulai dengan underscore `_`. Sebuah _prefix_ dibutuhkan untuk mencegah hal ini terjadi, karena Nano ID mungkin menggunakan `_` sebagai karakter pertama dari ID yang dihasilkan.
@@ -336,16 +311,6 @@ db.put({
})
```

### Mongoose

```js
const mySchema = new Schema({
_id: {
type: String,
default: () => nanoid()
}
})
```

### Web Workers

@@ -360,6 +325,7 @@ nanoid() //=> "Uakgb_J5m9g-0JDMbcJqLJ"

Perhatian: ID yang dihasilkan dari non-secure dapat lebih mudah tabrakan / memiliki probabilitas collision yang lebih besar.


### CLI

Nano ID dapat didapatkan dengan cara menggunakan `npx nanoid` pada Terminal. Hanya diperlukan Node.js untuk ini, dan tidak perlu mengunduh dan menginstall Nano ID dalam sistem.
@@ -372,6 +338,7 @@ LZfXLFzPPR4NNrgjlWDxn

Bila ingin mengganti alfabet atau ukuran ID, dapat menggunakan [`nanoid-cli`](https://github.com/twhitbeck/nanoid-cli).


### Bahasa Pemrograman Lainnya

Nano ID telah bermigrasi ke berbagai macam bahasa. Seluruh versi dapat digunakan untuk mendapatkan ID generator yang sama pada sisi klien dan sisi penyedia layanan (_client-side_ dan _server-side_).
@@ -404,6 +371,7 @@ Nano ID telah bermigrasi ke berbagai macam bahasa. Seluruh versi dapat digunakan

Untuk environment lainnya, [CLI](#cli) tersedia untuk melakukan generasi ID dari command line / Terminal.


## Alat

- [ID Size Calculator](https://zelark.github.io/nano-id-cc/) menunjukkan probabilitas collision ketika melakukan konfigurasi alfabet dan ukuran.
57 changes: 0 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -47,12 +47,9 @@ Supports modern browsers, IE [with Babel], Node.js and React Native.
* [Custom Alphabet or Size](#custom-alphabet-or-size)
* [Custom Random Bytes Generator](#custom-random-bytes-generator)
* [Usage](#usage)
* [IE](#ie)
* [React](#react)
* [React Native](#react-native)
* [Rollup](#rollup)
* [PouchDB and CouchDB](#pouchdb-and-couchdb)
* [Mongoose](#mongoose)
* [Web Workers](#web-workers)
* [CLI](#cli)
* [Other Programming Languages](#other-programming-languages)
@@ -156,12 +153,6 @@ as ESM in webpack, Rollup, Parcel, or Node.js.
import { nanoid } from 'nanoid'
```

In Node.js you can use CommonJS import:

```js
const { nanoid } = require('nanoid')
```


## API

@@ -324,26 +315,6 @@ the same result.

## Usage

### IE

If you support IE, you need to [transpile `node_modules`] by Babel
and add `crypto` alias:

```js
// polyfills.js
if (!window.crypto) {
window.crypto = window.msCrypto
}
```

```js
import './polyfills.js'
import { nanoid } from 'nanoid'
```

[transpile `node_modules`]: https://developer.epages.com/blog/coding/how-to-transpile-node-modules-with-babel-and-webpack-in-a-monorepo/


### React

There’s no correct way to use Nano ID for React `key` prop
@@ -402,22 +373,6 @@ import { nanoid } from 'nanoid'
[`react-native-get-random-values`]: https://github.com/LinusU/react-native-get-random-values


### Rollup

For Rollup you will need [`@rollup/plugin-node-resolve`] to bundle browser version
of this library.:

```js
plugins: [
nodeResolve({
browser: true
})
]
```

[`@rollup/plugin-node-resolve`]: https://github.com/rollup/plugins/tree/master/packages/node-resolve


### PouchDB and CouchDB

In PouchDB and CouchDB, IDs can’t start with an underscore `_`.
@@ -434,18 +389,6 @@ db.put({
```


### Mongoose

```js
const mySchema = new Schema({
_id: {
type: String,
default: () => nanoid()
}
})
```


### Web Workers

Web Workers do not have access to a secure random generator.
Loading