Skip to content

Commit ca2d244

Browse files
robhoganfacebook-github-bot
authored andcommitted
Align Flow lib defs for Node.js url with v24
Summary: This is an AI-assisted change to align the Flow definitions for the `url` module with the Node.js docs as at v24. **New Safe Parsing:** 1. **`URL.parse(input, base?)`** - Safe static parsing (added in v22.1.0) - Parses URL without throwing exceptions - Returns `URL` object on success, `null` on failure - Alternative to `new URL()` that doesn't require try-catch - Example: `const url = URL.parse(userInput); if (url) { ... }` - https://nodejs.org/api/url.html#urlparseinput-base **New Pattern Matching (Experimental):** 2. **`URLPattern` class** - Web API-compatible URL pattern matching (added in v23.8.0) 🧪 - Constructor: `new URLPattern(input?, options?)` or `new URLPattern(input, baseURL, options?)` - Properties: `protocol`, `username`, `password`, `hostname`, `port`, `pathname`, `search`, `hash`, `hasRegExpGroups` (all readonly) - Methods: - `test(input?, baseURL?)` - Returns boolean if URL matches pattern - `exec(input?, baseURL?)` - Returns match result with captured groups or null - Supports wildcard patterns (`*`), named groups (`:param`), and case-insensitive matching - Use cases: routing, URL filtering, path matching - https://nodejs.org/api/url.html#class-urlpattern **Enhanced Path Conversion:** 3. **`pathToFileURL(path, options?)`** - Enhanced with options (v20.0.0) - New optional `options` parameter: `{windows?: boolean}` - Enables cross-platform path conversion testing - https://nodejs.org/api/url.html#urlpathtofileurlpath-options 4. **`fileURLToPath(url, options?)`** - Enhanced with options (v20.0.0) - New optional `options` parameter: `{windows?: boolean}` - Enables cross-platform URL to path conversion testing - https://nodejs.org/api/url.html#urlfileurltopathurl-options **Type Definitions Added:** 5. **`url$URLPatternInit`** - Pattern initialization object - Optional properties for each URL component - Used in URLPattern constructor and exec/test methods 6. **`url$URLPatternComponentResult`** - Pattern match result for URL component - Contains `input` string and captured `groups` object 7. **`url$URLPatternResult`** - Complete pattern match result - Contains match results for all URL components - Includes original inputs array **References:** - Node.js url module docs: https://nodejs.org/api/url.html - URLPattern Web API spec: https://urlpattern.spec.whatwg.org/ Changelog: [Internal] --- > Generated by [Confucius Code Assist (CCA)](https://www.internalfb.com/wiki/Confucius/Analect/Shared_Analects/Confucius_Code_Assist_(CCA)/) [Confucius Session](https://www.internalfb.com/confucius?host=devvm45708.cln0.facebook.com&port=8086&tab=Chat&session_id=1a3aa26e-e5a9-11f0-8d47-71a4a90f0494&entry_name=Code+Assist), [Trace](https://www.internalfb.com/confucius?session_id=1a3aa26e-e5a9-11f0-8d47-71a4a90f0494&tab=Trace) Reviewed By: vzaidman Differential Revision: D89943253
1 parent 4862cc7 commit ca2d244

1 file changed

Lines changed: 68 additions & 2 deletions

File tree

flow-typed/environment/node.js

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,8 +3551,16 @@ declare module 'url' {
35513551
declare function resolve(from: string, to: string): string;
35523552
declare function domainToASCII(domain: string): string;
35533553
declare function domainToUnicode(domain: string): string;
3554-
declare function pathToFileURL(path: string): url$urlObject;
3555-
declare function fileURLToPath(path: url$urlObject | string): string;
3554+
3555+
declare function pathToFileURL(
3556+
path: string,
3557+
options?: Readonly<{windows?: boolean}>,
3558+
): url$urlObject;
3559+
3560+
declare function fileURLToPath(
3561+
path: url$urlObject | string,
3562+
options?: Readonly<{windows?: boolean}>,
3563+
): string;
35563564
declare class URLSearchParams {
35573565
@@iterator(): Iterator<[string, string]>;
35583566

@@ -3588,6 +3596,7 @@ declare module 'url' {
35883596
}
35893597
declare class URL {
35903598
static canParse(url: string, base?: string): boolean;
3599+
static parse(input: string, base?: string): URL | null;
35913600
static createObjectURL(blob: Blob): string;
35923601
static createObjectURL(mediaSource: MediaSource): string;
35933602
static revokeObjectURL(url: string): void;
@@ -3607,6 +3616,63 @@ declare module 'url' {
36073616
toString(): string;
36083617
toJSON(): string;
36093618
}
3619+
3620+
declare type url$URLPatternInit = {
3621+
protocol?: string,
3622+
username?: string,
3623+
password?: string,
3624+
hostname?: string,
3625+
port?: string,
3626+
pathname?: string,
3627+
search?: string,
3628+
hash?: string,
3629+
baseURL?: string,
3630+
};
3631+
3632+
declare type url$URLPatternComponentResult = {
3633+
input: string,
3634+
groups: {[key: string]: string | void},
3635+
};
3636+
3637+
declare type url$URLPatternResult = {
3638+
inputs: $ReadOnlyArray<string | url$URLPatternInit>,
3639+
protocol: url$URLPatternComponentResult,
3640+
username: url$URLPatternComponentResult,
3641+
password: url$URLPatternComponentResult,
3642+
hostname: url$URLPatternComponentResult,
3643+
port: url$URLPatternComponentResult,
3644+
pathname: url$URLPatternComponentResult,
3645+
search: url$URLPatternComponentResult,
3646+
hash: url$URLPatternComponentResult,
3647+
};
3648+
3649+
declare class URLPattern {
3650+
constructor(
3651+
input?: string | url$URLPatternInit,
3652+
options?: Readonly<{ignoreCase?: boolean}>,
3653+
): void;
3654+
constructor(
3655+
input: string | url$URLPatternInit,
3656+
baseURL: string,
3657+
options?: Readonly<{ignoreCase?: boolean}>,
3658+
): void;
3659+
3660+
+hasRegExpGroups: boolean;
3661+
+hash: string;
3662+
+hostname: string;
3663+
+password: string;
3664+
+pathname: string;
3665+
+port: string;
3666+
+protocol: string;
3667+
+search: string;
3668+
+username: string;
3669+
3670+
exec(
3671+
input?: string | url$URLPatternInit,
3672+
baseURL?: string,
3673+
): url$URLPatternResult | null;
3674+
test(input?: string | url$URLPatternInit, baseURL?: string): boolean;
3675+
}
36103676
}
36113677

36123678
type util$InspectOptions = {

0 commit comments

Comments
 (0)