Skip to content

Commit

Permalink
docs(monorepo): Updated @default tsdoc params to @defaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivanpj committed Jul 28, 2024
1 parent 46c83ca commit 85067dd
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 66 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,4 @@ jobs:
packageManagerVersion: 9.6.0
stormBot: Stormie-Bot
githubToken: ${{ github.token }}
secrets:
inherit

# githubToken: ${{ github.token }}
# npmToken: ${{ secrets.STORM_BOT_NPM_TOKEN }}
# cargoToken: ${{ secrets.STORM_BOT_CARGO_TOKEN }}
# slackToken: ${{ secrets.STORM_BOT_SLACK_TOKEN }}
# discordWebhook: ${{ secrets.STORM_BOT_DISCORD_WEBHOOK}}
secrets: inherit
23 changes: 10 additions & 13 deletions packages/date-time/src/storm-date-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface DateTimeOptions {
/**
* If false, the current date and time is defaulted when undefined or null is passed. If true, the current date and time is not defaulted.
*
* @default false
* @defaultValue false
*/
skipDefaulting?: boolean;
}
Expand Down Expand Up @@ -117,7 +117,7 @@ export class StormDateTime extends Date {
* @returns A new instance of StormDateTime with the maximum date and time.
*/
public static minimum(): StormDateTime {
return StormDateTime.create(new Date(-8640000000000000));
return StormDateTime.create(new Date(-8_640_000_000_000_000));
}

/**
Expand All @@ -126,7 +126,7 @@ export class StormDateTime extends Date {
* @returns A new instance of StormDateTime with the maximum date and time.
*/
public static maximum(): StormDateTime {
return StormDateTime.create(new Date(8640000000000000));
return StormDateTime.create(new Date(8_640_000_000_000_000));
}

/**
Expand Down Expand Up @@ -184,9 +184,8 @@ export class StormDateTime extends Date {
_dateTime = Temporal.Now.instant();
}

const instant = !_dateTime
? undefined
: StormDateTime.isDateTime(_dateTime)
const instant = _dateTime
? StormDateTime.isDateTime(_dateTime)
? _dateTime.instant
: Temporal.Instant.from(
isDate(_dateTime)
Expand All @@ -196,7 +195,8 @@ export class StormDateTime extends Date {
: isNumber(_dateTime) || isBigInt(_dateTime)
? new Date(Number(_dateTime)).toISOString()
: _dateTime
);
)
: undefined;

super(instant ? Number(instant.epochMilliseconds) : "MISSING_DATE");
if (instant && this.validate(_dateTime, options)) {
Expand Down Expand Up @@ -310,11 +310,8 @@ export class StormDateTime extends Date {
let datetime: string | undefined;
if (isDate(value) || isNumber(value) || isBigInt(value)) {
let date!: Date;
if (isNumber(value) || isBigInt(value)) {
date = new Date(Number(value));
} else {
date = value;
}
date =
isNumber(value) || isBigInt(value) ? new Date(Number(value)) : value;

if (Number.isNaN(date.getTime())) {
return false;
Expand Down Expand Up @@ -466,7 +463,7 @@ export class StormDateTime extends Date {
* Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC).
*/
public override getTimezoneOffset(): number {
return this.#zonedDateTime.offsetNanoseconds / 1000000;
return this.#zonedDateTime.offsetNanoseconds / 1_000_000;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-system/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ export interface PluginManagerOptions {
/**
* The path to the root of the application.
*
* @default process.env.STORM_WORKSPACE_ROOT
* @defaultValue process.env.STORM_WORKSPACE_ROOT
*/
rootPath: string;

/**
* The path to the root of the application.
*
* @default process.env.STORM_WORKSPACE_ROOT + "/tsconfig.json"
* @defaultValue process.env.STORM_WORKSPACE_ROOT + "/tsconfig.json"
*/
tsconfig?: string;

/**
* Should node_modules be used to discover plugins?
*
* @default true
* @defaultValue true
*/
useNodeModules: boolean;

/**
* Should auto-install be used to discover plugins?
*
* @default true
* @defaultValue true
*/
autoInstall: boolean;

Expand All @@ -48,7 +48,7 @@ export interface PluginManagerOptions {
* `fallback` - Discover plugins in the rootPath if a registered plugin provider is not found
* `none` - Do not discover plugins in the rootPath, regardless of whether a registered plugin provider is found or not
*
* @default "fallback"
* @defaultValue "fallback"
*/
discoveryMode: PluginDiscoveryMode;

Expand Down
23 changes: 12 additions & 11 deletions packages/unique-identifier/src/cuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { randomLetter } from "./random";
/**
* ~22k hosts before 50% chance of initial counter collision with a remaining counter range of 9.0e+15 in JavaScript.
*/
const INITIAL_COUNT_MAX = 476782367;
const INITIAL_COUNT_MAX = 476_782_367;

/**
* The length of the CUID fingerprint.
Expand All @@ -14,7 +14,7 @@ const CUID_LARGE_LENGTH = 36;
/**
* The sequence of the current running generator.
*
* @default 1
* @defaultValue 1
*/
const sequence = 1;

Expand Down Expand Up @@ -54,19 +54,20 @@ function fingerprint(
globalObj?: any;
} = {
globalObj:
typeof global !== "undefined"
? global
: typeof window !== "undefined"
? window
: {}
typeof global === "undefined"
? typeof window === "undefined"
? {}
: window
: global
}
) {
const globals = Object.keys(options.globalObj).toString();
const sourceString = globals.length
? globals + createEntropy(CUID_LARGE_LENGTH, Math.random)
: createEntropy(CUID_LARGE_LENGTH, Math.random);
const sourceString =
globals.length > 0
? globals + createEntropy(CUID_LARGE_LENGTH, Math.random)
: createEntropy(CUID_LARGE_LENGTH, Math.random);

return hash(sourceString).substring(0, CUID_LARGE_LENGTH);
return hash(sourceString).slice(0, Math.max(0, CUID_LARGE_LENGTH));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/unique-identifier/src/hash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sha3_512 } from "@noble/hashes/sha3";
import { isSet, isString } from "@storm-stack/utilities";
import { isSet, isString } from "@storm-stack/types";

/**
* Default radix for the BigInt.toString() method.
Expand Down
27 changes: 13 additions & 14 deletions packages/unique-identifier/src/snowflake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface ISnowflakeGeneratorOptions {
/**
* The id of the shard running this generator.
*
* @default 1
* @defaultValue 1
*/
shardId: number;

Expand All @@ -15,14 +15,14 @@ export interface ISnowflakeGeneratorOptions {
* @remarks
* This is the time in milliseconds since 1 January 1970 00:00:00 UTC.
*
* @default 1420070400000 (Date.UTC(1970, 0, 1).valueOf())
* @defaultValue 1420070400000 (Date.UTC(1970, 0, 1).valueOf())
*/
epoch: number;

/**
* The current timestamp to use for the snowflake.
*
* @default Date.now()
* @defaultValue Date.now()
*/
timestamp: number | Date;
}
Expand Down Expand Up @@ -73,7 +73,7 @@ const DEFAULT_EPOCH: number = Date.UTC(1970, 0, 1).valueOf();
/**
* The sequence of the current running generator.
*
* @default 1
* @defaultValue 1
*/
let sequence = 1;

Expand All @@ -88,7 +88,7 @@ function ToBinaryString(snowflake: SnowflakeResolvable): string {
"0000000000000000000000000000000000000000000000000000000000000000";
const binValue = BigInt(snowflake).toString(2);
return binValue.length < 64
? cached64BitZeros.substring(0, 64 - binValue.length) + binValue
? cached64BitZeros.slice(0, Math.max(0, 64 - binValue.length)) + binValue
: binValue;
}

Expand All @@ -104,10 +104,10 @@ function extractBits(
start: number,
length?: number
): number {
return parseInt(
return Number.parseInt(
length
? ToBinaryString(snowflake).substring(start, start + length)
: ToBinaryString(snowflake).substring(start),
: ToBinaryString(snowflake).slice(Math.max(0, start)),
2
);
}
Expand Down Expand Up @@ -147,11 +147,10 @@ export function snowflake(
timestamp: Date.now()
}
): string {
if (timestamp instanceof Date) {
timestamp = timestamp.valueOf();
} else {
timestamp = new Date(timestamp).valueOf();
}
timestamp =
timestamp instanceof Date
? timestamp.valueOf()
: new Date(timestamp).valueOf();

let result = (BigInt(timestamp) - BigInt(epoch)) << BigInt(22);
result = result | (BigInt(shardId % 1024) << BigInt(12));
Expand Down Expand Up @@ -187,15 +186,15 @@ export function deconstructSnowflake(
* @returns Whether the snowflake is valid
*/
export function isValidSnowflake(snowflake: string): boolean {
if (!/^[\d]{19}$/.test(snowflake)) {
if (!/^\d{19}$/.test(snowflake)) {
return false;
}

try {
deconstructSnowflake(snowflake);

return true;
} catch (_e) {
} catch {
return false;
}
}
31 changes: 17 additions & 14 deletions packages/unique-identifier/src/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { isSetString, isString, sha1 } from "@storm-stack/utilities";
import { isSetString, isString } from "@storm-stack/types";
import { sha1 } from "@storm-stack/utilities";

function stringToBytes(str: string | number | boolean) {
const _str = unescape(encodeURIComponent(str));
const bytes = [];

for (let i = 0; i < _str.length; ++i) {
bytes.push(_str.charCodeAt(i));
bytes.push(_str.codePointAt(i));
}

return bytes;
Expand All @@ -17,7 +18,7 @@ function stringToBytes(str: string | number | boolean) {
*/
const byteToHex: string[] = [];
for (let i = 0; i < 256; ++i) {
byteToHex.push((i + 0x100).toString(16).slice(1));
byteToHex.push((i + 0x1_00).toString(16).slice(1));
}

function unsafeStringify(arr: number[], offset = 0) {
Expand Down Expand Up @@ -77,43 +78,45 @@ const URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
function parse(uuid: string) {
if (
!isSetString(uuid) ||
/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i.test(
/^(?:[\da-f]{8}-[\da-f]{4}-[1-5][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}|0{8}-(?:0{4}-){3}0{12})$/i.test(
uuid
) === false
) {
throw TypeError("Invalid UUID");
throw new TypeError("Invalid UUID");
}

let value!: number;
const arr = new Uint8Array(16);

// Parse ########-....-....-....-............
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
arr[0] = (value = parseInt(uuid.slice(0, 8), 16)) >>> 24;
arr[0] = (value = Number.parseInt(uuid.slice(0, 8), 16)) >>> 24;
arr[1] = (value >>> 16) & 0xff;
arr[2] = (value >>> 8) & 0xff;
arr[3] = value & 0xff;

// Parse ........-####-....-....-............
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
arr[4] = (value = parseInt(uuid.slice(9, 13), 16)) >>> 8;
arr[4] = (value = Number.parseInt(uuid.slice(9, 13), 16)) >>> 8;
arr[5] = value & 0xff;

// Parse ........-....-####-....-............
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
arr[6] = (value = parseInt(uuid.slice(14, 18), 16)) >>> 8;
arr[6] = (value = Number.parseInt(uuid.slice(14, 18), 16)) >>> 8;
arr[7] = value & 0xff;

// Parse ........-....-....-####-............
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
arr[8] = (value = parseInt(uuid.slice(19, 23), 16)) >>> 8;
arr[8] = (value = Number.parseInt(uuid.slice(19, 23), 16)) >>> 8;
arr[9] = value & 0xff;

// Parse ........-....-....-....-############
// (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
arr[10] = ((value = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000) & 0xff;
arr[11] = (value / 0x100000000) & 0xff;
arr[10] =
((value = Number.parseInt(uuid.slice(24, 36), 16)) / 0x1_00_00_00_00_00) &
0xff;
arr[11] = (value / 0x1_00_00_00_00) & 0xff;
arr[12] = (value >>> 24) & 0xff;
arr[13] = (value >>> 16) & 0xff;
arr[14] = (value >>> 8) & 0xff;
Expand Down Expand Up @@ -160,7 +163,7 @@ function uuid5(
_namespace = parse(_namespace);
}
if (_namespace?.length !== 16) {
throw TypeError(
throw new TypeError(
"Namespace must be array-like (16 iterable integer values, 0-255)"
);
}
Expand Down Expand Up @@ -190,14 +193,14 @@ function uuid5(
return buf;
}

return unsafeStringify(Array.from(bytes));
return unsafeStringify([...bytes]);
}

// Function#name is not settable on some platforms (#270)
try {
generateUUID.name = name;
// eslint-disable-next-line no-empty
} catch (_) {}
} catch {}

// For CommonJS default export support
generateUUID.DNS = DNS;
Expand Down

0 comments on commit 85067dd

Please sign in to comment.