Skip to content

Commit

Permalink
break: use hexoid named export
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Jun 8, 2022
1 parent 43f5e28 commit cdbae71
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
3 changes: 1 addition & 2 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $ npm install --save hexoid
## Usage

```js
import hexoid from 'hexoid';
import { hexoid } from 'hexoid';

const toID = hexoid();
// length = 16 (default)
Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default function (len?: number): () => string;
export function hexoid(len?: number): () => string;
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
6 changes: 4 additions & 2 deletions test/collisions.js
Original file line number Diff line number Diff line change
@@ -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());
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down

0 comments on commit cdbae71

Please sign in to comment.