diff --git a/bin/build.js b/bin/build.js index 242c054..e95d97d 100644 --- a/bin/build.js +++ b/bin/build.js @@ -40,8 +40,7 @@ function transform(input, outputs) { write(outputs.import, data); // esm -> cjs -> minify - // data = data.replace('export function hexoid', 'exports.hexoid = function'); - data = data.replace('export default function', 'module.exports = function'); + data = data.replace('export function hexoid', 'exports.hexoid = function'); write(outputs.require, data); if (outputs.types) { diff --git a/readme.md b/readme.md index c906796..16e639c 100644 --- a/readme.md +++ b/readme.md @@ -21,7 +21,7 @@ $ npm install --save hexoid ## Usage ```js -import hexoid from 'hexoid'; +import { hexoid } from 'hexoid'; const toID = hexoid(); // length = 16 (default) diff --git a/src/index.d.ts b/src/index.d.ts index 9b03069..94c01dd 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1 +1 @@ -export default function (len?: number): () => string; +export function hexoid(len?: number): () => string; diff --git a/src/index.js b/src/index.js index b5e3fea..097e605 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ var IDX=256, HEX=[]; while (IDX--) HEX[IDX] = (IDX + 256).toString(16).substring(1); -export default function (len) { +export function hexoid(len) { len = len || 16; var str='', num=0; return function () { diff --git a/test/collisions.js b/test/collisions.js index 45c805e..61191dc 100644 --- a/test/collisions.js +++ b/test/collisions.js @@ -1,6 +1,8 @@ // $ node test/collisions 16 1e7 const [len=8, cycles] = process.argv.slice(2); -const hexoid = require('../dist')(len); +const { hexoid } = require('../dist'); + +const toUID = hexoid(len); const total = cycles ? +cycles : 1e6; console.log('~> item total:', total.toLocaleString()); @@ -9,7 +11,7 @@ console.log('~> hash length:', len); let sentry = new Set(); let i=0, tmp, duplicates=0; for (; i < total; i++) { - tmp = hexoid(); + tmp = toUID(); if (sentry.has(tmp)) { duplicates++; } else { diff --git a/test/index.js b/test/index.js index a8a5e80..ba099cf 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,6 @@ import { test } from 'uvu'; import * as assert from 'uvu/assert'; -import hexoid from '../src/index.js'; +import { hexoid } from '../src/index.js'; test('exports', () => { assert.type(hexoid, 'function', 'exports function');