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: 2.1.7
Choose a base ref
...
head repository: ai/nanoid
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.1.8
Choose a head ref
  • 12 commits
  • 9 files changed
  • 3 contributors

Commits on Nov 16, 2019

  1. Update sharec config

    ai committed Nov 16, 2019
    Copy the full SHA
    1cf77d3 View commit details
  2. Clean up code

    ai committed Nov 16, 2019
    Copy the full SHA
    16f15ed View commit details
  3. Normalize scripts style

    ai committed Nov 16, 2019
    Copy the full SHA
    a8b0d83 View commit details

Commits on Dec 7, 2019

  1. Bump serialize-to-js from 3.0.0 to 3.0.1 (#158)

    Bumps [serialize-to-js](https://github.com/commenthol/serialize-to-js) from 3.0.0 to 3.0.1.
    - [Release notes](https://github.com/commenthol/serialize-to-js/releases)
    - [Commits](commenthol/serialize-to-js@v3.0.0...v3.0.1)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and ai committed Dec 7, 2019
    Copy the full SHA
    c3ac1f4 View commit details

Commits on Dec 14, 2019

  1. Adding example for react using hooks (#159)

    * Adding example for react using hooks
    
    This helps to understand how to use nanoid in react with hooks.
    
    * using state instead of ref.
    nahumzs authored and ai committed Dec 14, 2019
    Copy the full SHA
    1ec3aa9 View commit details
  2. Simplify React example

    ai committed Dec 14, 2019
    Copy the full SHA
    d3e9e67 View commit details
  3. Clean up regexp

    ai committed Dec 14, 2019
    Copy the full SHA
    1c6dca5 View commit details
  4. Update dependencies

    ai committed Dec 14, 2019
    Copy the full SHA
    48f1415 View commit details
  5. Fix regexps in executables

    ai committed Dec 14, 2019
    Copy the full SHA
    0af2583 View commit details
  6. Copy the full SHA
    734910a View commit details
  7. Update geneticalgorithm

    ai committed Dec 14, 2019
    Copy the full SHA
    7e3dd89 View commit details
  8. Release 2.1.8 version

    ai committed Dec 14, 2019
    Copy the full SHA
    b270fbb View commit details
Showing with 1,020 additions and 977 deletions.
  1. +3 −0 CHANGELOG.md
  2. +4 −5 README.md
  3. +13 −13 package.json
  4. +4 −4 test/alphabet
  5. +31 −29 test/{alphabet-genetic.js → alphabet-genetic}
  6. +2 −3 test/alphabet-worker.js
  7. +2 −2 test/benchmark
  8. +2 −2 test/demo/index.js
  9. +959 −919 yarn.lock
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).

## 2.1.8
* Improve React docs (by Nahum Zsilva).

## 2.1.7
* Reduce `index`, `async` and `non-secure` size (by @polemius).

9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -176,13 +176,12 @@ between renders. This is bad code:
<Item key={nanoid()} /> /* DON’T DO IT */
```

This is good code. `this.id` will be generated only once:
This is good code. `id` will be generated only once:

```jsx
id = nanoid()
render () {
return <Item key={this.id}>;
}
const Element = () => {
const [id] = React.useState(nanoid)
return <Item key={id}>
}
```

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nanoid",
"version": "2.1.7",
"version": "2.1.8",
"description": "A tiny (137 bytes), secure URL-friendly unique string ID generator",
"keywords": [
"uuid",
@@ -31,30 +31,30 @@
},
"sideEffects": false,
"devDependencies": {
"@logux/eslint-config": "^34.0.1",
"@logux/sharec-config": "^0.5.5",
"@size-limit/preset-small-lib": "^2.2.1",
"@logux/eslint-config": "^35.0.1",
"@logux/sharec-config": "^0.5.6",
"@size-limit/preset-small-lib": "^2.2.2",
"benchmark": "^2.1.4",
"chalk": "^3.0.0",
"clean-publish": "^1.1.2",
"clean-publish": "^1.1.4",
"documentation": "^12.1.4",
"eslint": "^6.6.0",
"eslint": "^6.7.2",
"eslint-ci": "^1.0.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-es5": "^1.4.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^23.0.4",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jest": "^23.1.1",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-prefer-let": "^1.0.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-unicorn": "^13.0.0",
"geneticalgorithm": "^0.3.6",
"eslint-plugin-unicorn": "^14.0.1",
"geneticalgorithm": "^1.0.1",
"gzip-size": "^5.1.1",
"husky": "^3.0.9",
"husky": "^3.1.0",
"jest": "^24.9.0",
"lint-staged": "^9.4.3",
"lint-staged": "^9.5.0",
"parcel-bundler": "^1.12.4",
"rimraf": "^3.0.0",
"rndm": "^1.2.0",
@@ -169,6 +169,6 @@
},
"sharec": {
"config": "@logux/sharec-config",
"version": "0.5.3"
"version": "0.5.6"
}
}
8 changes: 4 additions & 4 deletions test/alphabet
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/node --experimental-worker
#!/usr/bin/node

const WORKERS = 8

let spawnSync = require('child_process').spawnSync
let Worker = require('worker_threads').Worker
let { spawnSync } = require('child_process')
let { Worker } = require('worker_threads')
let chalk = require('chalk')
let path = require('path')
let fs = require('fs')
@@ -20,7 +20,7 @@ spawnSync('npx', ['webpack', '--mode', 'production', '--output', output, input])
let js = fs.readFileSync(output).toString()
fs.unlinkSync(output)

let match = js.match(/[A-Za-z0-9-_]{30,}/)
let match = js.match(/[\w-]{30,}/)
if (!match) {
process.stderr.write(chalk.red('Alphabet was not found\n'))
process.exit(1)
60 changes: 31 additions & 29 deletions test/alphabet-genetic.js → test/alphabet-genetic
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
let spawnSync = require('child_process').spawnSync
#!/usr/bin/node

let geneticAlgorithmConstructor = require('geneticalgorithm')
let { spawnSync } = require('child_process')
let chalk = require('chalk')
let path = require('path')
let fs = require('fs')
let geneticAlgorithmConstructor = require('geneticalgorithm')
let gzipSize = require('gzip-size')

if (!process.argv[2]) {
@@ -17,7 +19,7 @@ spawnSync('npx', ['webpack', '--mode', 'production', '--output', output, input])
let js = fs.readFileSync(output).toString()
fs.unlinkSync(output)

let match = js.match(/[A-Za-z0-9-_]{30,}/)
let match = js.match(/[\w-]{30,}/)
if (!match) {
process.stderr.write(chalk.red('Alphabet was not found\n'))
process.exit(1)
@@ -27,35 +29,29 @@ let alphabet = match[0]
function mutationFunction (phenotype) {
let i = Math.floor(Math.random() * phenotype.alphabet.length)
let j = Math.floor(Math.random() * phenotype.alphabet.length)

return {
alphabet: swapChars(phenotype.alphabet, i, j)
}
return { alphabet: swapChars(phenotype.alphabet, i, j) }
}

function swapChars (str, index1, index2) {
let l = index1 < index2 ? index1 : index2
let h = index1 > index2 ? index1 : index2
return str.substring(0, l) +
str[h] +
str.substring(l + 1, h) +
str[l] +
str.substring(h + 1, str.length)
str[h] +
str.substring(l + 1, h) +
str[l] +
str.substring(h + 1, str.length)
}

function crossoverFunction (phenotypeA, phenotypeB) {
let alphabetA = phenotypeA.alphabet
let alphabetB = phenotypeB.alphabet
let indexA =
Math.floor(Math.random() * alphabetA.length / 2 + alphabetA.length / 2)
let indexB =
Math.floor(Math.random() + alphabetA.length / 2)
let newStrA = alphabetA.substring(indexA, alphabetA.length)
let newStrB = alphabetB.substring(0, indexB)

let a = phenotypeA.alphabet
let b = phenotypeB.alphabet
let indexA = Math.floor(Math.random() * a.length / 2 + a.length / 2)
let indexB = Math.floor(Math.random() + a.length / 2)
let newStrA = a.substring(indexA, a.length)
let newStrB = b.substring(0, indexB)
return [
{ alphabet: addMissingCharacter(newStrA, alphabetB) },
{ alphabet: addMissingCharacter(newStrB, alphabetA) }
{ alphabet: addMissingCharacter(newStrA, b) },
{ alphabet: addMissingCharacter(newStrB, a) }
]
}

@@ -70,7 +66,7 @@ function addMissingCharacter (str, proto) {
}

function fitnessFunction (phenotype) {
let file = js.replace(/[A-Za-z0-9-_]{30,}/, phenotype.alphabet)
let file = js.replace(/[\w-]{30,}/, phenotype.alphabet)
let size = gzipSize.sync(file)
console.log(size, phenotype.alphabet)
return -1 * size
@@ -104,9 +100,15 @@ for (let i = 0; i < 100; i++) {
const best = geneticAlgorithm.best()
console.log('Finished with:', best.alphabet)
const isSame = sameAlphabet(firstPhenotype.alphabet, best.alphabet)
console.log('Same set of characters:',
isSame ? chalk.green('true') : chalk.red('false'))
console.log(chalk.green('Size new string:',
gzipSize.sync(js.replace(/[A-Za-z0-9-_]{30,}/, best.alphabet))))
console.log(chalk.yellow('Size old string:',
gzipSize.sync(js.replace(/[A-Za-z0-9-_]{30,}/, firstPhenotype.alphabet))))
console.log(
'Same set of characters:',
isSame ? chalk.green('true') : chalk.red('false')
)
console.log(chalk.green(
'Size new string:',
gzipSize.sync(js.replace(/[\w-]{30,}/, best.alphabet))
))
console.log(chalk.yellow(
'Size old string:',
gzipSize.sync(js.replace(/[\w-]{30,}/, firstPhenotype.alphabet)))
)
5 changes: 2 additions & 3 deletions test/alphabet-worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
let parentPort = require('worker_threads').parentPort
let workerData = require('worker_threads').workerData
let { parentPort, workerData } = require('worker_threads')
let gzipSize = require('gzip-size')

let used = new Set()
@@ -60,7 +59,7 @@ function tick () {
steps += 1
let alphabet = getAlphabet(positions)
if (alphabet) {
let file = workerData.js.replace(/[A-Za-z0-9-_]{30,}/, alphabet)
let file = workerData.js.replace(/[\w-]{30,}/, alphabet)
gzipSize(file).then(size => {
parentPort.postMessage({ alphabet, steps, size })
steps = 0
4 changes: 2 additions & 2 deletions test/benchmark
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ let suite = new benchmark.Suite()

function formatNumber (number) {
return String(number)
.replace(/\d\d\d$/, ',$&')
.replace(/^(\d)(\d\d\d)/, '$1,$2')
.replace(/\d{3}$/, ',$&')
.replace(/^(\d)(\d{3})/, '$1,$2')
}

suite
4 changes: 2 additions & 2 deletions test/demo/index.js
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@ const LENGTH = ALPHABET.length

function print (number) {
return String(Math.floor(number * 100))
.replace(/\d\d\d\d\d\d$/, ',$&')
.replace(/\d\d\d$/, ',$&')
.replace(/\d{6}$/, ',$&')
.replace(/\d{3}$/, ',$&')
}

function printDistr (title, fn) {
1,878 changes: 959 additions & 919 deletions yarn.lock

Large diffs are not rendered by default.