Skip to content

Commit

Permalink
fix: expression is not constructable error on nodenext
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlescure committed Apr 30, 2024
1 parent e1433f9 commit a24af4b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 17 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const isValid = uid.validate(uuid);

console.log(`Is the UUID valid? ${isValid}`);

// -----------
// ---

// Validate the generated UUID against the provided dictionary
const customDictionary = ['a', 'b', /* ... */];
Expand Down Expand Up @@ -225,6 +225,12 @@ console.log(uid.rnd());

// Sequential UUID
console.log(uid.seq());

// ---

// Legacy support (Node 16 or less)
// or if using "Node16" as "module" or "moduleResolution" in "tsconfig.json"
const uid = new ShortUniqueId.default();
```

alternatively using destructuring assignment:
Expand Down
26 changes: 19 additions & 7 deletions dist/short-unique-id.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* @packageDocumentation
**/
export interface ShortUniqueIdRanges {
declare interface ShortUniqueIdRanges {
[k: string]: [number, number];
}
export interface ShortUniqueIdRangesMap {
declare interface ShortUniqueIdRangesMap {
[k: string]: ShortUniqueIdRanges;
}
export type ShortUniqueIdDefaultDictionaries = 'number' | 'alpha' | 'alpha_lower' | 'alpha_upper' | 'alphanum' | 'alphanum_lower' | 'alphanum_upper' | 'hex';
declare type ShortUniqueIdDefaultDictionaries = 'number' | 'alpha' | 'alpha_lower' | 'alpha_upper' | 'alphanum' | 'alphanum_lower' | 'alphanum_upper' | 'hex';
/**
* ```js
* {
Expand All @@ -20,7 +20,7 @@ export type ShortUniqueIdDefaultDictionaries = 'number' | 'alpha' | 'alpha_lower
* <br/>
* @see {@link DEFAULT_OPTIONS}
*/
export interface ShortUniqueIdOptions {
declare interface ShortUniqueIdOptions {
/** User-defined character dictionary */
dictionary: string[] | ShortUniqueIdDefaultDictionaries;
/** If true, sequentialUUID use the dictionary in the given order */
Expand All @@ -42,8 +42,8 @@ export interface ShortUniqueIdOptions {
* the probability of generating a duplicate in 1,000,000 rounds
* is ~0.00000002, or about 1 in 50,000,000.
*/
export declare const DEFAULT_UUID_LENGTH: number;
export declare const DEFAULT_OPTIONS: ShortUniqueIdOptions;
declare const DEFAULT_UUID_LENGTH: number;
declare const DEFAULT_OPTIONS: ShortUniqueIdOptions;
/**
* Generate random or sequential UUID of any length.
*
Expand Down Expand Up @@ -100,7 +100,17 @@ export declare const DEFAULT_OPTIONS: ShortUniqueIdOptions;
*
* For more information take a look at the [ShortUniqueIdOptions type definition](/interfaces/shortuniqueidoptions.html).
*/
export default class ShortUniqueId {
declare namespace ShortUniqueId {
export {
ShortUniqueIdRanges,
ShortUniqueIdRangesMap,
ShortUniqueIdDefaultDictionaries,
ShortUniqueIdOptions,
DEFAULT_UUID_LENGTH,
DEFAULT_OPTIONS
}
}
declare class ShortUniqueId {
/** @hidden */
static default: typeof ShortUniqueId;
counter: number;
Expand Down Expand Up @@ -280,3 +290,5 @@ export default class ShortUniqueId {
validate: (uid: string, dictionary?: string[] | ShortUniqueIdDefaultDictionaries) => boolean;
constructor(argOptions?: Partial<ShortUniqueIdOptions>);
}

export = ShortUniqueId;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"runkitExampleFilename": "./runkit.js",
"scripts": {
"test": "tsx ./src/test.ts",
"test:local": "tsx ./src/test.ts && tsx --tsconfig ./specs/tsconfig.json ./specs/import-esm.spec.ts && ./scripts/cjs-test",
"test:local": "tsx ./src/test.ts && tsx --tsconfig ./specs/esm/tsconfig.json ./specs/esm/import.spec.ts && ./scripts/cjs-test",
"build": "./scripts/build",
"docs": "./scripts/docs",
"release": "release-it"
Expand Down
2 changes: 1 addition & 1 deletion specs/require-cjs.spec.js → specs/cjs/require.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ShortUniqueId = require('../dist/short-unique-id');
const ShortUniqueId = require('../../dist/short-unique-id');

const suid = new ShortUniqueId({length: 3});

Expand Down
2 changes: 1 addition & 1 deletion specs/import-esm.spec.ts → specs/esm/import.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ShortUniqueId from '../dist/short-unique-id';
import ShortUniqueId from '../../dist/short-unique-id.js';

const suid = new ShortUniqueId({length: 3});

Expand Down
3 changes: 3 additions & 0 deletions specs/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
6 changes: 6 additions & 0 deletions specs/esm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext"
}
}
6 changes: 0 additions & 6 deletions specs/tsconfig.json

This file was deleted.

0 comments on commit a24af4b

Please sign in to comment.