Commit f5c1126
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: c26d6c6a8003a30b50443020b06228ce2a0128381 parent e73ab78 commit f5c1126
1 file changed
Lines changed: 51 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3683 | 3683 | | |
3684 | 3684 | | |
3685 | 3685 | | |
3686 | | - | |
3687 | | - | |
| 3686 | + | |
| 3687 | + | |
3688 | 3688 | | |
3689 | 3689 | | |
3690 | 3690 | | |
3691 | 3691 | | |
| 3692 | + | |
3692 | 3693 | | |
3693 | | - | |
| 3694 | + | |
3694 | 3695 | | |
3695 | 3696 | | |
3696 | | - | |
| 3697 | + | |
3697 | 3698 | | |
3698 | 3699 | | |
3699 | | - | |
3700 | | - | |
| 3700 | + | |
| 3701 | + | |
3701 | 3702 | | |
3702 | 3703 | | |
3703 | 3704 | | |
3704 | 3705 | | |
| 3706 | + | |
3705 | 3707 | | |
3706 | | - | |
| 3708 | + | |
3707 | 3709 | | |
3708 | 3710 | | |
3709 | 3711 | | |
3710 | | - | |
| 3712 | + | |
3711 | 3713 | | |
3712 | 3714 | | |
3713 | 3715 | | |
| |||
3733 | 3735 | | |
3734 | 3736 | | |
3735 | 3737 | | |
| 3738 | + | |
| 3739 | + | |
| 3740 | + | |
| 3741 | + | |
| 3742 | + | |
| 3743 | + | |
| 3744 | + | |
| 3745 | + | |
| 3746 | + | |
| 3747 | + | |
| 3748 | + | |
| 3749 | + | |
| 3750 | + | |
| 3751 | + | |
| 3752 | + | |
| 3753 | + | |
| 3754 | + | |
| 3755 | + | |
| 3756 | + | |
| 3757 | + | |
| 3758 | + | |
| 3759 | + | |
| 3760 | + | |
| 3761 | + | |
| 3762 | + | |
| 3763 | + | |
| 3764 | + | |
| 3765 | + | |
| 3766 | + | |
| 3767 | + | |
| 3768 | + | |
| 3769 | + | |
| 3770 | + | |
| 3771 | + | |
| 3772 | + | |
| 3773 | + | |
| 3774 | + | |
| 3775 | + | |
| 3776 | + | |
| 3777 | + | |
3736 | 3778 | | |
3737 | 3779 | | |
3738 | 3780 | | |
| |||
3745 | 3787 | | |
3746 | 3788 | | |
3747 | 3789 | | |
| 3790 | + | |
3748 | 3791 | | |
3749 | 3792 | | |
3750 | 3793 | | |
| |||
0 commit comments