Skip to content

Commit f5c1126

Browse files
robhoganmeta-codesync[bot]
authored andcommitted
Align Flow lib defs for Node.js util with v24 (#55016)
Summary: Pull Request resolved: #55016 This is an AI-assisted change to align the Flow definitions for the `util` module with the Node.js docs as at v24. **New v20-v24 APIs:** 1. **`parseEnv(content)`** - Environment file (.env) parser (added in v20.12.0) - Parses `.env` file content into key-value object - Last value wins for duplicate keys - https://nodejs.org/api/util.html#utilparseenvcontent 2. **`diff(actual, expected)`** - String/array comparison (added in v22.15.0) 🧪 - Uses Myers diff algorithm for comparison - Returns array of tuples: `[operation: -1 | 0 | 1, value: string]` - `-1` = expected only (deletion) - `0` = both (unchanged) - `1` = actual only (insertion) - Experimental API - https://nodejs.org/api/util.html#utildiffactual-expected 3. **`getSystemErrorMessage(err)`** - Error code to message (added in v22.12.0) - Returns the error message string for a numeric error code - https://nodejs.org/api/util.html#utilgetsystemerrormessageerr 4. **`getCallSites([frameCount | options])`** - Call stack capture (added in v22.9.0) - Captures call stack as `CallSiteObject` instances with: - `functionName`, `scriptName`, `scriptId`, `lineNumber`, `columnNumber` - `scriptId` property added in v22.14.0 - https://nodejs.org/api/util.html#utilgetcallsitesframecount 5. **`types.isFloat16Array()`** - Type check for Float16Array (added in v24.0.0) - Checks if value is a Float16Array instance - https://nodejs.org/api/util.html#utiltypesisfloat16arrayvalue **New Classes (v19):** 6. **`MIMEType` class** - MIME type parsing and manipulation (added in v19.1.0, v18.13.0) - Properties: `type`, `subtype`, `essence`, `params` - Methods: `toString()` - Implements MIMEType proposal spec - https://nodejs.org/api/util.html#class-utilmimetype 7. **`MIMEParams` class** - MIME parameters handler (added in v19.1.0, v18.13.0) - Methods: `delete()`, `get()`, `has()`, `set()`, `entries()`, `keys()`, `values()` - https://nodejs.org/api/util.html#class-utilmimeparams **Updated APIs:** 8. **`parseArgs()` - Added `allowNegative` option** (added in v22.4.0) - Allows explicitly setting boolean options to false with `--no-` prefix - Example: `--no-verbose` sets `verbose: false` - https://nodejs.org/api/util.html#utilparseargsconfig **Type Safety Improvements:** 9. **Exact-by-default syntax** - Simplified object types - Changed `{|...|}` `{}` in parseArgs types (Flow configured with exact-by-default) - Changed default generic types from `{||}` → `{}` 10. **styleText()** already present with full type definitions - 18 foreground colors, 18 background colors, 12 modifiers - https://nodejs.org/api/util.html#utilstyletextformat-text **References:** - Node.js util module docs: https://nodejs.org/api/util.html - MIMEType proposal: https://bmeck.github.io/node-proposal-mime-api/ 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: D89942136 fbshipit-source-id: c26d6c6a8003a30b50443020b06228ce2a012838
1 parent e73ab78 commit f5c1126

1 file changed

Lines changed: 51 additions & 8 deletions

File tree

flow-typed/environment/node.js

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,31 +3683,33 @@ declare module 'util' {
36833683
declare function stripVTControlCharacters(str: string): string;
36843684

36853685
declare function parseArgs<
3686-
TOptions: {+[string]: util$ParseArgsOption} = {||},
3687-
>(config: {|
3686+
TOptions: {+[string]: util$ParseArgsOption} = {},
3687+
>(config: {
36883688
args?: Array<string>,
36893689
options?: TOptions,
36903690
strict?: boolean,
36913691
allowPositionals?: boolean,
3692+
allowNegative?: boolean,
36923693
tokens?: false,
3693-
|}): {|
3694+
}): {
36943695
values: util$ParseArgsOptionsToValues<TOptions>,
36953696
positionals: Array<string>,
3696-
|};
3697+
};
36973698

36983699
declare function parseArgs<
3699-
TOptions: {[string]: util$ParseArgsOption} = {||},
3700-
>(config: {|
3700+
TOptions: {[string]: util$ParseArgsOption} = {},
3701+
>(config: {
37013702
args?: Array<string>,
37023703
options?: TOptions,
37033704
strict?: boolean,
37043705
allowPositionals?: boolean,
3706+
allowNegative?: boolean,
37053707
tokens: true,
3706-
|}): {|
3708+
}): {
37073709
values: util$ParseArgsOptionsToValues<TOptions>,
37083710
positionals: Array<string>,
37093711
tokens: Array<util$ParseArgsToken>,
3710-
|};
3712+
};
37113713

37123714
declare class TextDecoder {
37133715
constructor(
@@ -3733,6 +3735,46 @@ declare module 'util' {
37333735
encoding: string;
37343736
}
37353737

3738+
declare class MIMEType {
3739+
constructor(input: string): void;
3740+
type: string;
3741+
subtype: string;
3742+
+essence: string;
3743+
+params: MIMEParams;
3744+
toString(): string;
3745+
}
3746+
3747+
declare class MIMEParams {
3748+
delete(name: string): void;
3749+
get(name: string): ?string;
3750+
has(name: string): boolean;
3751+
set(name: string, value: string): void;
3752+
entries(): Iterator<[string, string]>;
3753+
keys(): Iterator<string>;
3754+
values(): Iterator<string>;
3755+
}
3756+
3757+
declare function parseEnv(content: string): {[key: string]: string, ...};
3758+
3759+
declare type util$DiffEntry = [operation: -1 | 0 | 1, value: string];
3760+
declare function diff(
3761+
actual: string | $ReadOnlyArray<string>,
3762+
expected: string | $ReadOnlyArray<string>,
3763+
): Array<util$DiffEntry>;
3764+
3765+
declare function getSystemErrorMessage(err: number): string;
3766+
3767+
declare type util$CallSiteObject = {
3768+
functionName: string,
3769+
scriptName: string,
3770+
scriptId: string,
3771+
lineNumber: number,
3772+
columnNumber: number,
3773+
};
3774+
declare function getCallSites(
3775+
frameCountOrOptions?: number | Readonly<{frameCount?: number}>,
3776+
): Array<util$CallSiteObject>;
3777+
37363778
declare var types: {
37373779
isAnyArrayBuffer: (value: unknown) => boolean,
37383780
isArgumentsObject: (value: unknown) => boolean,
@@ -3745,6 +3787,7 @@ declare module 'util' {
37453787
isDataView: (value: unknown) => boolean,
37463788
isDate: (value: unknown) => boolean,
37473789
isExternal: (value: unknown) => boolean,
3790+
isFloat16Array: (value: unknown) => boolean,
37483791
isFloat32Array: (value: unknown) => boolean,
37493792
isFloat64Array: (value: unknown) => boolean,
37503793
isGeneratorFunction: (value: unknown) => boolean,

0 commit comments

Comments
 (0)