Skip to content

Commit

Permalink
refactor: Move constants to object
Browse files Browse the repository at this point in the history
  • Loading branch information
oculus42 committed May 1, 2024
1 parent cac43d3 commit 9ad09b1
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
const { v4: uuidV4 } = require('uuid');
const anyBase = require('any-base');

const cookieBase90 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*+-./:<=>?@[]^_`{|}~";
const flickrBase58 = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
const uuid25Base36 = '0123456789abcdefghijklmnopqrstuvwxyz';
const constants = {
cookieBase90: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*+-./:<=>?@[]^_`{|}~",
flickrBase58: '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ',
uuid25Base36: '0123456789abcdefghijklmnopqrstuvwxyz',
};

const baseOptions = {
consistentLength: true,
Expand Down Expand Up @@ -68,7 +70,7 @@ module.exports = (() => {
*/
const makeConvertor = (toAlphabet, options) => {
// Default to Flickr 58
const useAlphabet = toAlphabet || flickrBase58;
const useAlphabet = toAlphabet || constants.flickrBase58;

// Default to baseOptions
const selectedOptions = { ...baseOptions, ...options };
Expand Down Expand Up @@ -108,11 +110,7 @@ module.exports = (() => {
};

// Expose the constants for other purposes.
makeConvertor.constants = {
cookieBase90,
flickrBase58,
uuid25Base36,
};
makeConvertor.constants = constants;

// Expose the generic v4 UUID generator for convenience
makeConvertor.uuid = uuidV4;
Expand All @@ -121,7 +119,7 @@ module.exports = (() => {
makeConvertor.generate = () => {
if (!toFlickr) {
// Generate on first use;
toFlickr = makeConvertor(flickrBase58).generate;
toFlickr = makeConvertor(constants.flickrBase58).generate;
}
return toFlickr();
};
Expand Down

0 comments on commit 9ad09b1

Please sign in to comment.