Skip to content

Commit

Permalink
Add support for named exports (#67)
Browse files Browse the repository at this point in the history
Fixes: #58
  • Loading branch information
perrin4869 authored and brendanashworth committed Nov 8, 2021
1 parent 9512306 commit b8c6141
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.6.1",
"description": "Easy library for generating unique passwords.",
"main": "main.js",
"exports": "./main.js",
"types": "src/generate.d.ts",
"scripts": {
"test": "./node_modules/.bin/mocha",
Expand Down
8 changes: 3 additions & 5 deletions src/generate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
var crypto = require('crypto');

var self = module.exports;

const RANDOM_BATCH_SIZE = 256;

var randomIndex;
Expand Down Expand Up @@ -77,7 +75,7 @@ var generate = function(options, pool) {
};

// Generate a random password.
self.generate = function(options) {
module.exports.generate = function(options) {
// Set defaults.
options = options || {};
if (!Object.prototype.hasOwnProperty.call(options, 'length')) options.length = 10;
Expand Down Expand Up @@ -143,11 +141,11 @@ self.generate = function(options) {
};

// Generates multiple passwords at once with the same options.
self.generateMultiple = function(amount, options) {
module.exports.generateMultiple = function(amount, options) {
var passwords = [];

for (var i = 0; i < amount; i++) {
passwords[i] = self.generate(options);
passwords[i] = module.exports.generate(options);
}

return passwords;
Expand Down
13 changes: 13 additions & 0 deletions test/esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import chai from 'chai';
import { generate, generateMultiple } from 'generate-password';

const { assert } = chai;

describe('generate-password', function() {
describe('import()', function() {
it('should correctly import with named exports', function() {
assert.isFunction(generate);
assert.isFunction(generateMultiple);
});
});
});

0 comments on commit b8c6141

Please sign in to comment.