Skip to content

Commit fe20241

Browse files
Fix esm output
1 parent c58408d commit fe20241

4 files changed

Lines changed: 32 additions & 52 deletions

File tree

dist/index.esm.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
Object.defineProperty(exports, "__esModule", { value: true });
2-
exports.ulid = undefined;
3-
exports.replaceCharAt = replaceCharAt;
4-
exports.incrementBase32 = incrementBase32;
5-
exports.randomChar = randomChar;
6-
exports.encodeTime = encodeTime;
7-
exports.encodeRandom = encodeRandom;
8-
exports.decodeTime = decodeTime;
9-
exports.detectPrng = detectPrng;
10-
exports.factory = factory;
11-
exports.monotonicFactory = monotonicFactory;
121
function createError(message) {
132
const err = new Error(message);
143
err.source = "ulid";
@@ -164,4 +153,6 @@ function monotonicFactory(currPrng) {
164153
return encodeTime(seedTime, TIME_LEN) + newRandom;
165154
};
166155
}
167-
exports.ulid = factory();
156+
const ulid = factory();
157+
158+
export { decodeTime, detectPrng, encodeRandom, encodeTime, factory, incrementBase32, monotonicFactory, randomChar, replaceCharAt, ulid };

dist/index.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
"use strict";
2-
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.ulid = void 0;
4-
exports.replaceCharAt = replaceCharAt;
5-
exports.incrementBase32 = incrementBase32;
6-
exports.randomChar = randomChar;
7-
exports.encodeTime = encodeTime;
8-
exports.encodeRandom = encodeRandom;
9-
exports.decodeTime = decodeTime;
10-
exports.detectPrng = detectPrng;
11-
exports.factory = factory;
12-
exports.monotonicFactory = monotonicFactory;
131
function createError(message) {
142
const err = new Error(message);
153
err.source = "ulid";
@@ -22,13 +10,13 @@ const ENCODING_LEN = ENCODING.length;
2210
const TIME_MAX = Math.pow(2, 48) - 1;
2311
const TIME_LEN = 10;
2412
const RANDOM_LEN = 16;
25-
function replaceCharAt(str, index, char) {
13+
export function replaceCharAt(str, index, char) {
2614
if (index > str.length - 1) {
2715
return str;
2816
}
2917
return str.substr(0, index) + char + str.substr(index + 1);
3018
}
31-
function incrementBase32(str) {
19+
export function incrementBase32(str) {
3220
let done = undefined;
3321
let index = str.length;
3422
let char;
@@ -51,14 +39,14 @@ function incrementBase32(str) {
5139
}
5240
throw createError("cannot increment this string");
5341
}
54-
function randomChar(prng) {
42+
export function randomChar(prng) {
5543
let rand = Math.floor(prng() * ENCODING_LEN);
5644
if (rand === ENCODING_LEN) {
5745
rand = ENCODING_LEN - 1;
5846
}
5947
return ENCODING.charAt(rand);
6048
}
61-
function encodeTime(now, len) {
49+
export function encodeTime(now, len) {
6250
if (isNaN(now)) {
6351
throw new Error(now + " must be a number");
6452
}
@@ -80,14 +68,14 @@ function encodeTime(now, len) {
8068
}
8169
return str;
8270
}
83-
function encodeRandom(len, prng) {
71+
export function encodeRandom(len, prng) {
8472
let str = "";
8573
for (; len > 0; len--) {
8674
str = randomChar(prng) + str;
8775
}
8876
return str;
8977
}
90-
function decodeTime(id) {
78+
export function decodeTime(id) {
9179
if (id.length !== TIME_LEN + RANDOM_LEN) {
9280
throw createError("malformed ulid");
9381
}
@@ -107,7 +95,7 @@ function decodeTime(id) {
10795
}
10896
return time;
10997
}
110-
function detectPrng(allowInsecure = false, root) {
98+
export function detectPrng(allowInsecure = false, root) {
11199
if (!root) {
112100
root = typeof window !== "undefined" ? window : null;
113101
}
@@ -135,7 +123,7 @@ function detectPrng(allowInsecure = false, root) {
135123
}
136124
throw createError("secure crypto unusable, insecure Math.random not allowed");
137125
}
138-
function factory(currPrng) {
126+
export function factory(currPrng) {
139127
if (!currPrng) {
140128
currPrng = detectPrng();
141129
}
@@ -146,7 +134,7 @@ function factory(currPrng) {
146134
return encodeTime(seedTime, TIME_LEN) + encodeRandom(RANDOM_LEN, currPrng);
147135
};
148136
}
149-
function monotonicFactory(currPrng) {
137+
export function monotonicFactory(currPrng) {
150138
if (!currPrng) {
151139
currPrng = detectPrng();
152140
}
@@ -165,4 +153,4 @@ function monotonicFactory(currPrng) {
165153
return encodeTime(seedTime, TIME_LEN) + newRandom;
166154
};
167155
}
168-
exports.ulid = factory();
156+
export const ulid = factory();

dist/index.umd.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
(function (factory) {
2-
typeof define === 'function' && define.amd ? define(factory) :
3-
factory();
4-
})((function () { 'use strict';
1+
(function (global, factory) {
2+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
4+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ULID = {}));
5+
})(this, (function (exports) { 'use strict';
56

6-
Object.defineProperty(exports, "__esModule", { value: true });
7-
exports.ulid = undefined;
8-
exports.replaceCharAt = replaceCharAt;
9-
exports.incrementBase32 = incrementBase32;
10-
exports.randomChar = randomChar;
11-
exports.encodeTime = encodeTime;
12-
exports.encodeRandom = encodeRandom;
13-
exports.decodeTime = decodeTime;
14-
exports.detectPrng = detectPrng;
15-
exports.factory = factory;
16-
exports.monotonicFactory = monotonicFactory;
177
function createError(message) {
188
const err = new Error(message);
199
err.source = "ulid";
@@ -169,6 +159,17 @@
169159
return encodeTime(seedTime, TIME_LEN) + newRandom;
170160
};
171161
}
172-
exports.ulid = factory();
162+
const ulid = factory();
163+
164+
exports.decodeTime = decodeTime;
165+
exports.detectPrng = detectPrng;
166+
exports.encodeRandom = encodeRandom;
167+
exports.encodeTime = encodeTime;
168+
exports.factory = factory;
169+
exports.incrementBase32 = incrementBase32;
170+
exports.monotonicFactory = monotonicFactory;
171+
exports.randomChar = randomChar;
172+
exports.replaceCharAt = replaceCharAt;
173+
exports.ulid = ulid;
173174

174175
}));

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"types": ["node"],
55
"declaration": true,
66
"target": "ES6",
7-
"module": "node16",
8-
"moduleResolution": "node16",
7+
"module": "es6",
8+
"moduleResolution": "node",
99
"outDir": "./dist"
1010
},
1111
"include": [

0 commit comments

Comments
 (0)