@socketsecurity/lib 6.0.3 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/_virtual/_rolldown/runtime.js +45 -0
- package/dist/abort/signal.js +53 -59
- package/dist/ai/discover.js +110 -110
- package/dist/ai/profiles.js +94 -65
- package/dist/ai/spawn.js +172 -194
- package/dist/ai/types.js +1 -17
- package/dist/ai/worktree.js +160 -183
- package/dist/ansi/constants.js +16 -38
- package/dist/ansi/strip.js +44 -41
- package/dist/archives/_internal.js +64 -73
- package/dist/archives/detect.js +30 -43
- package/dist/archives/extract.js +43 -50
- package/dist/archives/tar.js +197 -228
- package/dist/archives/types.js +1 -17
- package/dist/archives/zip.js +85 -121
- package/dist/argv/flag-predicates.js +203 -101
- package/dist/argv/flag-types.js +96 -113
- package/dist/argv/parse-args-string.d.ts +16 -14
- package/dist/argv/parse-args-string.js +42 -39
- package/dist/argv/parse.js +145 -163
- package/dist/arrays/_internal.js +65 -48
- package/dist/arrays/chunk.js +51 -40
- package/dist/arrays/join.js +87 -35
- package/dist/arrays/predicates.js +46 -28
- package/dist/arrays/unique.js +45 -31
- package/dist/bin/_internal.js +34 -42
- package/dist/bin/check-primordials.js +175 -233
- package/dist/bin/check.js +51 -72
- package/dist/bin/exec.js +70 -74
- package/dist/bin/find.js +151 -134
- package/dist/bin/resolve.js +180 -246
- package/dist/bin/shadow.js +24 -33
- package/dist/bin/socket-lib.js +51 -73
- package/dist/bin/types.js +1 -17
- package/dist/bin/which.js +211 -146
- package/dist/cacache/_internal.js +25 -40
- package/dist/cacache/clear.js +79 -72
- package/dist/cacache/read.js +48 -46
- package/dist/cacache/tmp.js +29 -36
- package/dist/cacache/types.js +1 -17
- package/dist/cacache/write.js +43 -48
- package/dist/cache/ttl/store.js +232 -288
- package/dist/cache/ttl/types.js +1 -17
- package/dist/checks/primordials-defaults.js +83 -89
- package/dist/checks/primordials.js +225 -277
- package/dist/colors/convert.js +45 -37
- package/dist/colors/palette.js +88 -45
- package/dist/colors/socket-palette.js +74 -84
- package/dist/colors/types.js +1 -17
- package/dist/compression/_internal.js +57 -72
- package/dist/compression/brotli.js +94 -127
- package/dist/compression/gzip.js +95 -121
- package/dist/compression/types.js +1 -17
- package/dist/constants/agents.js +61 -113
- package/dist/constants/encoding.js +19 -42
- package/dist/constants/github.js +12 -30
- package/dist/constants/licenses.js +48 -63
- package/dist/constants/lifecycle-script-names.js +31 -45
- package/dist/constants/maintained-node-versions.js +22 -37
- package/dist/constants/node.js +226 -167
- package/dist/constants/package-default-node-range.js +16 -41
- package/dist/constants/package-default-socket-categories.js +12 -30
- package/dist/constants/packages.js +77 -126
- package/dist/constants/platform.js +27 -49
- package/dist/constants/sentinels.js +23 -48
- package/dist/constants/socket.js +42 -87
- package/dist/constants/testing.js +15 -34
- package/dist/constants/time.js +16 -36
- package/dist/constants/typescript.js +32 -52
- package/dist/cover/code.js +111 -142
- package/dist/cover/formatters.js +118 -101
- package/dist/cover/type.js +50 -76
- package/dist/cover/types.js +1 -17
- package/dist/crypto/hash.js +54 -46
- package/dist/debug/_internal.js +62 -71
- package/dist/debug/caller-info.js +53 -64
- package/dist/debug/namespace.js +80 -90
- package/dist/debug/output.js +172 -188
- package/dist/debug/types.js +1 -17
- package/dist/dlx/_internal.js +24 -43
- package/dist/dlx/arborist.js +162 -160
- package/dist/dlx/binary-cache.js +228 -200
- package/dist/dlx/binary-download.js +172 -211
- package/dist/dlx/binary-resolution.js +165 -157
- package/dist/dlx/binary-types.js +1 -17
- package/dist/dlx/binary.js +149 -189
- package/dist/dlx/cache.js +45 -30
- package/dist/dlx/detect.js +245 -159
- package/dist/dlx/dir.js +67 -51
- package/dist/dlx/firewall.js +62 -100
- package/dist/dlx/lockfile.js +122 -127
- package/dist/dlx/manifest.js +264 -274
- package/dist/dlx/package.js +241 -244
- package/dist/dlx/packages.js +99 -96
- package/dist/dlx/paths.js +73 -59
- package/dist/dlx/spec.js +52 -60
- package/dist/dlx/types.js +1 -17
- package/dist/eco/cargo/lockfile-format.js +19 -36
- package/dist/eco/cargo/manifest-format.js +17 -35
- package/dist/eco/cargo/parse-lockfile.js +210 -237
- package/dist/eco/manifest/analyze-lockfile.js +46 -63
- package/dist/eco/manifest/detect-format.js +66 -90
- package/dist/eco/manifest/find-packages.js +39 -64
- package/dist/eco/manifest/get-package-versions.js +27 -48
- package/dist/eco/manifest/get-package.js +21 -40
- package/dist/eco/manifest/manifest-error.js +14 -35
- package/dist/eco/manifest/parse-lockfile.js +40 -86
- package/dist/eco/manifest/parse-manifest.js +26 -43
- package/dist/eco/manifest/parse.js +26 -47
- package/dist/eco/manifest/types.js +1 -17
- package/dist/eco/npm/bun/exec.js +23 -32
- package/dist/eco/npm/manifest-format.js +21 -35
- package/dist/eco/npm/npm/exec.js +51 -61
- package/dist/eco/npm/npm/extract-package-name-from-path.js +28 -50
- package/dist/eco/npm/npm/flags.js +80 -52
- package/dist/eco/npm/npm/lockfile-format.js +21 -40
- package/dist/eco/npm/npm/parse-git-url.js +26 -40
- package/dist/eco/npm/npm/parse-lockfile.js +184 -210
- package/dist/eco/npm/parse-package-json.js +71 -102
- package/dist/eco/npm/pnpm/detect-pnpm-version.js +22 -43
- package/dist/eco/npm/pnpm/exec.js +51 -62
- package/dist/eco/npm/pnpm/flags.js +75 -68
- package/dist/eco/npm/pnpm/lockfile-format.js +19 -36
- package/dist/eco/npm/pnpm/parse-lockfile.js +235 -259
- package/dist/eco/npm/pnpm/parse-pnpm-package-id-v5.js +37 -47
- package/dist/eco/npm/pnpm/parse-pnpm-package-id-v6-v9.js +36 -49
- package/dist/eco/npm/script.js +82 -90
- package/dist/eco/npm/vlt/exec.js +24 -32
- package/dist/eco/npm/yarnpkg/yarn/exec.js +60 -59
- package/dist/eco/npm/yarnpkg/yarn/lockfile-format.js +20 -36
- package/dist/eco/npm/yarnpkg/yarn/parse-lockfile.js +194 -242
- package/dist/eco/npm/yarnpkg/yarn/parse-yarn-descriptor.js +37 -61
- package/dist/eco/purl.js +50 -60
- package/dist/eco/types.js +1 -17
- package/dist/effects/pulse-frames.js +64 -65
- package/dist/effects/shimmer-keyframes.js +71 -52
- package/dist/effects/shimmer-terminal.js +81 -50
- package/dist/effects/shimmer.js +290 -153
- package/dist/env/boolean.js +42 -43
- package/dist/env/case-insensitive.js +54 -39
- package/dist/env/ci.js +29 -31
- package/dist/env/debug.js +28 -31
- package/dist/env/github.js +144 -59
- package/dist/env/home.js +38 -31
- package/dist/env/locale.js +59 -39
- package/dist/env/node-auth-token.js +28 -31
- package/dist/env/node-env.js +28 -31
- package/dist/env/npm.js +94 -47
- package/dist/env/number.js +50 -51
- package/dist/env/package-manager.js +95 -83
- package/dist/env/path.js +28 -31
- package/dist/env/pre-commit.js +30 -32
- package/dist/env/proxy.js +121 -122
- package/dist/env/rewire.js +204 -96
- package/dist/env/shell.js +28 -31
- package/dist/env/socket-cli.js +233 -81
- package/dist/env/socket.js +521 -156
- package/dist/env/string.js +43 -44
- package/dist/env/temp-dir.js +59 -39
- package/dist/env/term.js +28 -31
- package/dist/env/test.js +65 -43
- package/dist/env/types.js +1 -17
- package/dist/env/windows.js +78 -43
- package/dist/env/xdg.js +62 -39
- package/dist/errors/message.js +40 -46
- package/dist/errors/predicates.js +61 -49
- package/dist/errors/stack.js +24 -36
- package/dist/events/exit/_internal.js +86 -103
- package/dist/events/exit/handler.js +48 -55
- package/dist/events/exit/intercept.js +49 -70
- package/dist/events/exit/lifecycle.js +92 -101
- package/dist/events/exit/signals.js +25 -31
- package/dist/events/exit/types.js +1 -17
- package/dist/events/warning/handler.js +43 -40
- package/dist/events/warning/suppress.js +111 -90
- package/dist/external/@npmcli/package-json/lib/read-package.js +132 -153
- package/dist/external/@npmcli/package-json/lib/sort.js +73 -105
- package/dist/external/@npmcli/package-json.js +12705 -15140
- package/dist/external/@npmcli/promise-spawn.js +451 -472
- package/dist/external/@sinclair/typebox/value.js +7443 -9002
- package/dist/external/@sinclair/typebox.js +7516 -7885
- package/dist/external/@socketregistry/is-unicode-supported.js +31 -39
- package/dist/external/@socketregistry/packageurl-js.js +6127 -7369
- package/dist/external/@socketregistry/yocto-spinner.js +394 -455
- package/dist/external/@yarnpkg/extensions.js +435 -1022
- package/dist/external/adm-zip.js +2313 -2673
- package/dist/external/debug.js +700 -687
- package/dist/external/external-pack.js +2658 -3171
- package/dist/external/fast-sort.js +124 -138
- package/dist/external/get-east-asian-width.js +70 -64
- package/dist/external/libnpmexec.js +28 -31
- package/dist/external/npm-pack.js +43617 -50137
- package/dist/external/p-map.js +198 -222
- package/dist/external/pico-pack.js +6735 -7304
- package/dist/external/pony-cause.js +143 -139
- package/dist/external/shell-quote.js +226 -0
- package/dist/external/spdx-pack.js +1283 -1403
- package/dist/external/streaming-iterables.js +835 -1052
- package/dist/external/tar-fs.js +2769 -3048
- package/dist/external/which.js +267 -251
- package/dist/external/yargs-parser.js +851 -1074
- package/dist/external-tools/bazel/asset-names.js +98 -90
- package/dist/external-tools/bazel/from-download.js +52 -46
- package/dist/external-tools/bazel/from-path.js +27 -38
- package/dist/external-tools/bazel/read-bazel-version-file.js +35 -57
- package/dist/external-tools/bazel/resolve-asset-url.js +24 -39
- package/dist/external-tools/bazel/resolve-bazel-version.js +34 -56
- package/dist/external-tools/bazel/resolve.js +44 -58
- package/dist/external-tools/bazel/types.js +1 -17
- package/dist/external-tools/cdxgen/asset-names.js +59 -66
- package/dist/external-tools/cdxgen/from-download.js +52 -80
- package/dist/external-tools/cdxgen/from-path.js +19 -37
- package/dist/external-tools/cdxgen/from-vfs.js +22 -43
- package/dist/external-tools/cdxgen/resolve.js +48 -63
- package/dist/external-tools/cdxgen/types.js +1 -17
- package/dist/external-tools/from-download.js +107 -67
- package/dist/external-tools/janus/asset-names.js +44 -51
- package/dist/external-tools/janus/from-download.js +45 -70
- package/dist/external-tools/janus/from-path.js +19 -37
- package/dist/external-tools/janus/from-vfs.js +22 -43
- package/dist/external-tools/janus/resolve.js +45 -63
- package/dist/external-tools/janus/types.js +1 -17
- package/dist/external-tools/jre/asset-names.js +109 -82
- package/dist/external-tools/jre/detect-platform-arch.js +25 -49
- package/dist/external-tools/jre/from-download.js +71 -67
- package/dist/external-tools/jre/from-java-home.js +27 -54
- package/dist/external-tools/jre/from-path.js +27 -49
- package/dist/external-tools/jre/from-vfs.js +39 -60
- package/dist/external-tools/jre/resolve.js +55 -68
- package/dist/external-tools/jre/types.js +1 -17
- package/dist/external-tools/manifest.js +130 -150
- package/dist/external-tools/opengrep/asset-names.js +60 -72
- package/dist/external-tools/opengrep/from-download.js +58 -80
- package/dist/external-tools/opengrep/from-path.js +19 -37
- package/dist/external-tools/opengrep/from-vfs.js +23 -43
- package/dist/external-tools/opengrep/resolve.js +43 -63
- package/dist/external-tools/opengrep/types.js +1 -17
- package/dist/external-tools/sbt/asset-names.js +21 -30
- package/dist/external-tools/sbt/from-download.js +50 -61
- package/dist/external-tools/sbt/from-path.js +23 -38
- package/dist/external-tools/sbt/from-vfs.js +30 -44
- package/dist/external-tools/sbt/resolve.js +45 -63
- package/dist/external-tools/sbt/types.js +1 -17
- package/dist/external-tools/synp/asset-names.js +11 -29
- package/dist/external-tools/synp/from-download.js +24 -41
- package/dist/external-tools/synp/from-path.js +19 -37
- package/dist/external-tools/synp/from-vfs.js +22 -43
- package/dist/external-tools/synp/resolve.js +43 -62
- package/dist/external-tools/synp/types.js +1 -17
- package/dist/external-tools/trivy/asset-names.js +51 -62
- package/dist/external-tools/trivy/from-download.js +42 -64
- package/dist/external-tools/trivy/from-path.js +19 -37
- package/dist/external-tools/trivy/from-vfs.js +22 -43
- package/dist/external-tools/trivy/resolve.js +43 -63
- package/dist/external-tools/trivy/types.js +1 -17
- package/dist/external-tools/trufflehog/asset-names.js +54 -66
- package/dist/external-tools/trufflehog/from-download.js +44 -62
- package/dist/external-tools/trufflehog/from-path.js +21 -37
- package/dist/external-tools/trufflehog/from-vfs.js +26 -43
- package/dist/external-tools/trufflehog/resolve.js +43 -63
- package/dist/external-tools/trufflehog/types.js +1 -17
- package/dist/external-tools/uv/asset-names.js +64 -74
- package/dist/external-tools/uv/from-download.js +44 -65
- package/dist/external-tools/uv/from-path.js +19 -37
- package/dist/external-tools/uv/from-vfs.js +22 -43
- package/dist/external-tools/uv/resolve.js +42 -63
- package/dist/external-tools/uv/types.js +1 -17
- package/dist/fs/_internal.js +40 -42
- package/dist/fs/access.js +57 -54
- package/dist/fs/encoding.js +80 -97
- package/dist/fs/find-up.js +126 -125
- package/dist/fs/inspect.js +168 -99
- package/dist/fs/path-cache.js +31 -32
- package/dist/fs/read-dir.js +102 -79
- package/dist/fs/read-file.js +177 -118
- package/dist/fs/read-json-cache.js +150 -134
- package/dist/fs/read-json.js +172 -187
- package/dist/fs/resolve-module.js +35 -58
- package/dist/fs/safe.js +278 -169
- package/dist/fs/types.js +1 -17
- package/dist/fs/unique.js +52 -48
- package/dist/fs/validate.js +56 -40
- package/dist/fs/write-json.js +109 -75
- package/dist/git/_internal.js +251 -216
- package/dist/git/changed.js +191 -74
- package/dist/git/repo.js +118 -104
- package/dist/git/staged.js +172 -62
- package/dist/git/types.js +1 -17
- package/dist/git/unstaged.js +175 -62
- package/dist/github/constants.js +25 -33
- package/dist/github/errors.js +46 -38
- package/dist/github/fetch.js +137 -82
- package/dist/github/ghsa.js +217 -151
- package/dist/github/refs-cache.js +54 -43
- package/dist/github/refs-graphql.js +97 -89
- package/dist/github/refs-rest.js +70 -101
- package/dist/github/refs.js +105 -64
- package/dist/github/token.js +96 -48
- package/dist/github/types.js +1 -17
- package/dist/globs/_internal.js +73 -82
- package/dist/globs/defaults.js +40 -59
- package/dist/globs/match.js +93 -77
- package/dist/globs/matcher.js +104 -92
- package/dist/globs/stream.js +43 -55
- package/dist/globs/types.js +1 -17
- package/dist/http-request/_internal.js +11 -38
- package/dist/http-request/browser-fetch.js +19 -29
- package/dist/http-request/browser.js +188 -206
- package/dist/http-request/checksums.js +101 -65
- package/dist/http-request/download-types.js +1 -17
- package/dist/http-request/download.js +195 -196
- package/dist/http-request/errors.js +39 -47
- package/dist/http-request/headers.js +95 -80
- package/dist/http-request/http-request.js +10 -35
- package/dist/http-request/node.js +71 -97
- package/dist/http-request/request-attempt.js +232 -285
- package/dist/http-request/request-types.js +1 -17
- package/dist/http-request/request.js +106 -108
- package/dist/http-request/response-reader.js +47 -51
- package/dist/http-request/response-types.js +22 -38
- package/dist/http-request/user-agent.js +73 -55
- package/dist/integrity.js +105 -106
- package/dist/ipc/_internal.js +34 -48
- package/dist/ipc/directory.js +55 -63
- package/dist/ipc/paths.js +52 -45
- package/dist/ipc/types.js +1 -17
- package/dist/ipc/write.js +81 -74
- package/dist/ipc-cli/get.js +29 -56
- package/dist/ipc-cli/types.js +1 -17
- package/dist/json/edit.js +182 -242
- package/dist/json/format.js +202 -103
- package/dist/json/parse.js +206 -109
- package/dist/json/types.js +1 -17
- package/dist/links/create.js +93 -60
- package/dist/links/types.js +1 -17
- package/dist/logger/_internal.js +109 -73
- package/dist/logger/browser.js +45 -56
- package/dist/logger/colors.js +31 -49
- package/dist/logger/console.js +89 -112
- package/dist/logger/default.js +19 -33
- package/dist/logger/logger.js +5 -29
- package/dist/logger/node.js +794 -854
- package/dist/logger/symbols-builder.js +54 -56
- package/dist/logger/symbols.js +135 -118
- package/dist/logger/types.js +1 -17
- package/dist/memo/_internal.js +39 -49
- package/dist/memo/async.js +133 -117
- package/dist/memo/clear.js +25 -34
- package/dist/memo/decorator.js +43 -37
- package/dist/memo/memoize.js +97 -88
- package/dist/memo/once.js +42 -41
- package/dist/memo/types.js +1 -17
- package/dist/memo/weak.js +45 -41
- package/dist/node/async-hooks.js +9 -30
- package/dist/node/child-process.js +9 -30
- package/dist/node/crypto.js +9 -30
- package/dist/node/events.js +9 -30
- package/dist/node/fs-promises.js +9 -30
- package/dist/node/fs.js +9 -30
- package/dist/node/http.js +9 -30
- package/dist/node/https.js +9 -30
- package/dist/node/module.js +20 -34
- package/dist/node/os.js +9 -30
- package/dist/node/path.js +9 -30
- package/dist/node/timers-promises.js +9 -30
- package/dist/node/url.js +9 -30
- package/dist/node/util.js +9 -30
- package/dist/objects/getters.js +185 -126
- package/dist/objects/inspect.js +85 -52
- package/dist/objects/mutate.js +96 -76
- package/dist/objects/predicates.js +112 -59
- package/dist/objects/sort.js +120 -76
- package/dist/objects/types.js +1 -17
- package/dist/packages/edit-class.js +198 -265
- package/dist/packages/edit.js +79 -86
- package/dist/packages/exports.js +146 -157
- package/dist/packages/isolation.js +159 -209
- package/dist/packages/licenses.js +207 -189
- package/dist/packages/manifest.js +134 -172
- package/dist/packages/normalize.js +91 -102
- package/dist/packages/operations.d.ts +2 -0
- package/dist/packages/operations.js +283 -254
- package/dist/packages/provenance.js +195 -245
- package/dist/packages/specs.js +94 -84
- package/dist/packages/types.js +1 -17
- package/dist/packages/validation.js +49 -50
- package/dist/paths/_internal.js +82 -86
- package/dist/paths/conversion.js +112 -65
- package/dist/paths/dirnames.js +17 -42
- package/dist/paths/exts.js +23 -54
- package/dist/paths/filenames.js +21 -50
- package/dist/paths/globs.js +15 -38
- package/dist/paths/normalize.js +215 -236
- package/dist/paths/packages.js +34 -49
- package/dist/paths/predicates.js +184 -106
- package/dist/paths/resolve.js +146 -128
- package/dist/paths/rewire.js +108 -72
- package/dist/paths/socket.js +252 -132
- package/dist/paths/walk.js +55 -60
- package/dist/perf/_internal.js +10 -28
- package/dist/perf/enabled.js +21 -30
- package/dist/perf/metrics.js +81 -67
- package/dist/perf/report.js +79 -80
- package/dist/perf/timer.js +180 -126
- package/dist/perf/types.js +1 -17
- package/dist/pkg-ext/data.js +29 -82
- package/dist/pkg-ext/types.js +1 -17
- package/dist/primordials/array.js +120 -198
- package/dist/primordials/buffer.js +28 -51
- package/dist/primordials/date.js +26 -51
- package/dist/primordials/error.js +33 -59
- package/dist/primordials/function.js +21 -41
- package/dist/primordials/globals.js +25 -48
- package/dist/primordials/json.js +14 -30
- package/dist/primordials/map-set.js +88 -152
- package/dist/primordials/math.js +59 -116
- package/dist/primordials/number.js +41 -76
- package/dist/primordials/object.js +56 -116
- package/dist/primordials/promise.js +28 -52
- package/dist/primordials/reflect.js +24 -52
- package/dist/primordials/regexp.js +25 -47
- package/dist/primordials/string.js +114 -167
- package/dist/primordials/symbol.js +40 -72
- package/dist/primordials/uncurry.js +38 -55
- package/dist/primordials/url.js +27 -66
- package/dist/process/_internal.js +7 -32
- package/dist/process/abort.js +29 -35
- package/dist/process/lock-instance.js +26 -30
- package/dist/process/lock-manager.js +279 -307
- package/dist/process/lock-types.js +1 -17
- package/dist/process/spawn/_internal.js +43 -55
- package/dist/process/spawn/child.js +172 -211
- package/dist/process/spawn/errors.js +116 -113
- package/dist/process/spawn/stdio.js +51 -35
- package/dist/process/spawn/types.js +1 -17
- package/dist/process/transient.js +49 -66
- package/dist/promises/_internal.js +31 -34
- package/dist/promises/iterate.js +238 -102
- package/dist/promises/options.js +123 -101
- package/dist/promises/queue.js +115 -136
- package/dist/promises/resolvers.js +77 -46
- package/dist/promises/retry.js +156 -101
- package/dist/promises/types.js +1 -17
- package/dist/regexps/escape.js +32 -30
- package/dist/regexps/hex.js +16 -33
- package/dist/regexps/spec.js +53 -81
- package/dist/releases/github-archives.js +127 -118
- package/dist/releases/github-asset-url.js +162 -146
- package/dist/releases/github-assets.js +37 -49
- package/dist/releases/github-auth.js +32 -48
- package/dist/releases/github-downloads.js +118 -138
- package/dist/releases/github-listing.js +175 -145
- package/dist/releases/github-retry-config.js +41 -47
- package/dist/releases/github-types.js +1 -17
- package/dist/releases/socket-btm.js +273 -192
- package/dist/schema/parse.js +35 -36
- package/dist/schema/types.js +1 -17
- package/dist/schema/validate.js +118 -99
- package/dist/sea/detect.js +57 -52
- package/dist/secrets/_internal.js +86 -67
- package/dist/secrets/find.js +96 -77
- package/dist/secrets/keychain.js +315 -309
- package/dist/secrets/linux.js +133 -135
- package/dist/secrets/macos.js +151 -147
- package/dist/secrets/rc.js +182 -181
- package/dist/secrets/socket-api-token.js +28 -43
- package/dist/secrets/types.js +1 -17
- package/dist/secrets/windows.js +184 -242
- package/dist/shadow/skip.js +51 -70
- package/dist/shadow/types.js +1 -17
- package/dist/shell/parse.d.ts +26 -0
- package/dist/shell/parse.js +35 -0
- package/dist/shell/quote.d.ts +19 -0
- package/dist/shell/quote.js +30 -0
- package/dist/smol/detect.js +67 -43
- package/dist/smol/http.js +33 -37
- package/dist/smol/https.js +31 -37
- package/dist/smol/manifest.js +33 -37
- package/dist/smol/path.js +33 -37
- package/dist/smol/primordial.js +35 -37
- package/dist/smol/purl.js +34 -37
- package/dist/smol/versions.js +31 -37
- package/dist/smol/vfs.js +46 -38
- package/dist/sorts/_internal.js +14 -40
- package/dist/sorts/natural.js +57 -64
- package/dist/sorts/semver.js +33 -43
- package/dist/sorts/strings.js +24 -30
- package/dist/sorts/types.js +1 -17
- package/dist/spinner/default.js +72 -63
- package/dist/spinner/format.js +86 -71
- package/dist/spinner/spinner.js +749 -797
- package/dist/spinner/types.js +1 -17
- package/dist/spinner/with.js +193 -137
- package/dist/ssri/convert.js +64 -47
- package/dist/ssri/parse.js +38 -37
- package/dist/ssri/validate.js +51 -34
- package/dist/stdio/_internal.js +50 -46
- package/dist/stdio/clear.js +208 -86
- package/dist/stdio/divider.js +170 -97
- package/dist/stdio/footer.js +116 -110
- package/dist/stdio/header.js +117 -90
- package/dist/stdio/progress.js +189 -218
- package/dist/stdio/prompts.js +244 -168
- package/dist/stdio/stderr.js +173 -78
- package/dist/stdio/stdout.js +177 -94
- package/dist/streams/parallel.js +58 -50
- package/dist/streams/transform.js +36 -45
- package/dist/strings/format.js +145 -63
- package/dist/strings/predicates.js +56 -34
- package/dist/strings/search.js +52 -42
- package/dist/strings/transform.js +113 -72
- package/dist/strings/types.js +1 -17
- package/dist/strings/width.js +89 -82
- package/dist/tables/bordered.js +81 -81
- package/dist/tables/padding.js +36 -46
- package/dist/tables/simple.js +62 -70
- package/dist/tables/types.js +1 -17
- package/dist/temporal/instant.js +72 -81
- package/dist/temporal/now.js +40 -31
- package/dist/temporal/slots.js +42 -36
- package/dist/temporal/system.js +36 -36
- package/dist/temporal/temporal.js +11 -41
- package/dist/themes/context.js +131 -69
- package/dist/themes/resolve.js +207 -132
- package/dist/themes/themes.js +225 -194
- package/dist/themes/types.js +1 -17
- package/dist/url/parse.js +48 -51
- package/dist/url/predicates.js +24 -31
- package/dist/url/search-params.js +133 -101
- package/dist/url/types.js +1 -17
- package/dist/versions/_internal.js +31 -33
- package/dist/versions/compare.js +80 -58
- package/dist/versions/modify.js +41 -39
- package/dist/versions/parse.js +88 -64
- package/dist/versions/range.js +58 -41
- package/dist/versions/types.js +1 -17
- package/dist/words/article.js +22 -30
- package/dist/words/capitalize.js +25 -34
- package/dist/words/pluralize.js +23 -31
- package/dist/words/types.js +1 -17
- package/package.json +17 -5
package/dist/json/format.js
CHANGED
|
@@ -1,124 +1,223 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* Socket Lib - Built with
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
-
var format_exports = {};
|
|
22
|
-
__export(format_exports, {
|
|
23
|
-
INDENT_SYMBOL: () => INDENT_SYMBOL,
|
|
24
|
-
NEWLINE_SYMBOL: () => NEWLINE_SYMBOL,
|
|
25
|
-
detectIndent: () => detectIndent,
|
|
26
|
-
detectNewline: () => detectNewline,
|
|
27
|
-
extractFormatting: () => extractFormatting,
|
|
28
|
-
getDefaultFormatting: () => getDefaultFormatting,
|
|
29
|
-
getFormattingFromContent: () => getFormattingFromContent,
|
|
30
|
-
shouldSave: () => shouldSave,
|
|
31
|
-
sortKeys: () => sortKeys,
|
|
32
|
-
stringifyWithFormatting: () => stringifyWithFormatting,
|
|
33
|
-
stripFormattingSymbols: () => stripFormattingSymbols
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(format_exports);
|
|
36
|
-
var import_json = require("../primordials/json");
|
|
37
|
-
var import_object = require("../primordials/object");
|
|
2
|
+
/* Socket Lib - Built with rolldown */
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_primordials_object = require('../primordials/object.js');
|
|
5
|
+
const require_primordials_json = require('../primordials/json.js');
|
|
6
|
+
|
|
7
|
+
//#region src/json/format.ts
|
|
8
|
+
/**
|
|
9
|
+
* @file Shared utilities for JSON formatting preservation and manipulation.
|
|
10
|
+
* Provides functions for detecting and preserving indentation, line endings,
|
|
11
|
+
* and determining when JSON files should be saved based on content changes.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Symbols used to store formatting metadata in JSON objects.
|
|
15
|
+
*/
|
|
38
16
|
const INDENT_SYMBOL = Symbol.for("indent");
|
|
39
17
|
const NEWLINE_SYMBOL = Symbol.for("newline");
|
|
18
|
+
/**
|
|
19
|
+
* Detect indentation from a JSON string. Supports space-based indentation
|
|
20
|
+
* (returns count) or mixed indentation (returns string).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ;```ts
|
|
24
|
+
* detectIndent('{\n "key": "value"\n}') // => 2
|
|
25
|
+
* detectIndent('{\n "key": "value"\n}') // => 4
|
|
26
|
+
* detectIndent('{\n\t"key": "value"\n}') // => '\t'
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param json - JSON string to analyze.
|
|
30
|
+
*
|
|
31
|
+
* @returns Number of spaces or indentation string, defaults to 2 if not
|
|
32
|
+
* detected.
|
|
33
|
+
*/
|
|
40
34
|
function detectIndent(json) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (/^ +$/.test(indent)) {
|
|
47
|
-
return indent.length;
|
|
48
|
-
}
|
|
49
|
-
return indent;
|
|
35
|
+
const match = json.match(/^[{[][\r\n]+(\s+)/m);
|
|
36
|
+
if (!match) return 2;
|
|
37
|
+
const indent = match[1];
|
|
38
|
+
if (/^ +$/.test(indent)) return indent.length;
|
|
39
|
+
return indent;
|
|
50
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Detect newline character(s) from a JSON string. Supports LF (\n) and CRLF
|
|
43
|
+
* (\r\n) line endings.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ;```ts
|
|
47
|
+
* detectNewline('{\n "key": "value"\n}') // => '\n'
|
|
48
|
+
* detectNewline('{\r\n "key": "value"\r\n}') // => '\r\n'
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param json - JSON string to analyze.
|
|
52
|
+
*
|
|
53
|
+
* @returns Line ending string ('\n' or '\r\n'), defaults to '\n' if not
|
|
54
|
+
* detected.
|
|
55
|
+
*/
|
|
51
56
|
function detectNewline(json) {
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
const match = json.match(/\r?\n/);
|
|
58
|
+
return match ? match[0] : "\n";
|
|
54
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Extract formatting metadata from a JSON string.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ;```ts
|
|
65
|
+
* const formatting = extractFormatting('{\n "key": "value"\n}')
|
|
66
|
+
* // => { indent: 2, newline: '\n' }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @param json - JSON string to analyze.
|
|
70
|
+
*
|
|
71
|
+
* @returns Object containing indent and newline formatting
|
|
72
|
+
*/
|
|
55
73
|
function extractFormatting(json) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
74
|
+
return {
|
|
75
|
+
indent: detectIndent(json),
|
|
76
|
+
newline: detectNewline(json)
|
|
77
|
+
};
|
|
60
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Get default formatting for JSON files.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ;```typescript
|
|
84
|
+
* const fmt = getDefaultFormatting()
|
|
85
|
+
* // { indent: 2, newline: '\n' }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @returns Default formatting (2 spaces, LF line endings)
|
|
89
|
+
*/
|
|
61
90
|
function getDefaultFormatting() {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
91
|
+
return {
|
|
92
|
+
indent: 2,
|
|
93
|
+
newline: "\n"
|
|
94
|
+
};
|
|
66
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Extract formatting from content object that has symbol-based metadata.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ;```typescript
|
|
101
|
+
* const content = {
|
|
102
|
+
* [Symbol.for('indent')]: 4,
|
|
103
|
+
* [Symbol.for('newline')]: '\r\n',
|
|
104
|
+
* }
|
|
105
|
+
* getFormattingFromContent(content) // { indent: 4, newline: "\r\n" }
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @param content - Content object with Symbol.for('indent') and
|
|
109
|
+
* Symbol.for('newline')
|
|
110
|
+
*
|
|
111
|
+
* @returns Formatting metadata, or defaults if symbols not present
|
|
112
|
+
*/
|
|
67
113
|
function getFormattingFromContent(content) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
114
|
+
const indent = content[INDENT_SYMBOL];
|
|
115
|
+
const newline = content[NEWLINE_SYMBOL];
|
|
116
|
+
return {
|
|
117
|
+
indent: indent === void 0 || indent === null ? 2 : indent,
|
|
118
|
+
newline: newline === void 0 || newline === null ? "\n" : newline
|
|
119
|
+
};
|
|
74
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Determine if content should be saved based on changes and options. Compares
|
|
123
|
+
* current content with original content and respects options like
|
|
124
|
+
* ignoreWhitespace and sort.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ;```ts
|
|
128
|
+
* const current = { key: 'new-value', [Symbol.for('indent')]: 2 }
|
|
129
|
+
* const original = { key: 'old-value', [Symbol.for('indent')]: 2 }
|
|
130
|
+
* shouldSave(current, original, '{\n "key": "old-value"\n}\n')
|
|
131
|
+
* // => true
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @param currentContent - Current content object (may include formatting
|
|
135
|
+
* symbols)
|
|
136
|
+
* @param originalContent - Original content for comparison (may include
|
|
137
|
+
* formatting symbols)
|
|
138
|
+
* @param originalFileContent - Original file content as string (for whitespace
|
|
139
|
+
* comparison)
|
|
140
|
+
* @param options - Options controlling save behavior.
|
|
141
|
+
*
|
|
142
|
+
* @returns True if content should be saved, false otherwise
|
|
143
|
+
*/
|
|
75
144
|
function shouldSave(currentContent, originalContent, originalFileContent, options = {}) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return !util.isDeepStrictEqual(sortedContent, origContent);
|
|
83
|
-
}
|
|
84
|
-
const formatting = getFormattingFromContent(currentContent);
|
|
85
|
-
const newFileContent = stringifyWithFormatting(sortedContent, formatting);
|
|
86
|
-
return newFileContent.trim() !== originalFileContent.trim();
|
|
145
|
+
const { ignoreWhitespace = false, sort = false, sortFn } = options;
|
|
146
|
+
const content = stripFormattingSymbols(currentContent);
|
|
147
|
+
const sortedContent = sortFn ? sortFn(content) : sort ? sortKeys(content) : content;
|
|
148
|
+
const origContent = originalContent ? stripFormattingSymbols(originalContent) : {};
|
|
149
|
+
if (ignoreWhitespace) return !require("node:util").isDeepStrictEqual(sortedContent, origContent);
|
|
150
|
+
return stringifyWithFormatting(sortedContent, getFormattingFromContent(currentContent)).trim() !== originalFileContent.trim();
|
|
87
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Sort object keys alphabetically. Creates a new object with sorted keys (does
|
|
154
|
+
* not mutate input).
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ;```ts
|
|
158
|
+
* sortKeys({ z: 3, a: 1, m: 2 })
|
|
159
|
+
* // => { a: 1, m: 2, z: 3 }
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* @param obj - Object to sort.
|
|
163
|
+
*
|
|
164
|
+
* @returns New object with alphabetically sorted keys
|
|
165
|
+
*/
|
|
88
166
|
function sortKeys(obj) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
return sorted;
|
|
167
|
+
const sorted = { __proto__: null };
|
|
168
|
+
const keys = require_primordials_object.ObjectKeys(obj).sort();
|
|
169
|
+
for (const key of keys) sorted[key] = obj[key];
|
|
170
|
+
return sorted;
|
|
95
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Stringify JSON with specific formatting. Applies indentation and line ending
|
|
174
|
+
* preferences.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ;```ts
|
|
178
|
+
* stringifyWithFormatting({ key: 'value' }, { indent: 4, newline: '\r\n' })
|
|
179
|
+
* // => '{\r\n "key": "value"\r\n}\r\n'
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @param content - Object to stringify.
|
|
183
|
+
* @param formatting - Formatting preferences (indent and newline)
|
|
184
|
+
*
|
|
185
|
+
* @returns Formatted JSON string with trailing newline
|
|
186
|
+
*/
|
|
96
187
|
function stringifyWithFormatting(content, formatting) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
`.replace(/\n/g, eol);
|
|
188
|
+
const { indent, newline } = formatting;
|
|
189
|
+
const format = indent === void 0 || indent === null ? " " : indent;
|
|
190
|
+
const eol = newline === void 0 || newline === null ? "\n" : newline;
|
|
191
|
+
return `${require_primordials_json.JSONStringify(content, void 0, format)}\n`.replace(/\n/g, eol);
|
|
102
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Strip formatting symbols from content object. Removes Symbol.for('indent')
|
|
195
|
+
* and Symbol.for('newline') from the object.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ;```typescript
|
|
199
|
+
* const obj = { key: 'value', [Symbol.for('indent')]: 2 }
|
|
200
|
+
* stripFormattingSymbols(obj) // { key: "value" }
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @param content - Content object with potential symbol properties.
|
|
204
|
+
*
|
|
205
|
+
* @returns Object with symbols removed
|
|
206
|
+
*/
|
|
103
207
|
function stripFormattingSymbols(content) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
[NEWLINE_SYMBOL]: _newline,
|
|
107
|
-
...rest
|
|
108
|
-
} = content;
|
|
109
|
-
return rest;
|
|
208
|
+
const { [INDENT_SYMBOL]: _indent, [NEWLINE_SYMBOL]: _newline, ...rest } = content;
|
|
209
|
+
return rest;
|
|
110
210
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
});
|
|
211
|
+
|
|
212
|
+
//#endregion
|
|
213
|
+
exports.INDENT_SYMBOL = INDENT_SYMBOL;
|
|
214
|
+
exports.NEWLINE_SYMBOL = NEWLINE_SYMBOL;
|
|
215
|
+
exports.detectIndent = detectIndent;
|
|
216
|
+
exports.detectNewline = detectNewline;
|
|
217
|
+
exports.extractFormatting = extractFormatting;
|
|
218
|
+
exports.getDefaultFormatting = getDefaultFormatting;
|
|
219
|
+
exports.getFormattingFromContent = getFormattingFromContent;
|
|
220
|
+
exports.shouldSave = shouldSave;
|
|
221
|
+
exports.sortKeys = sortKeys;
|
|
222
|
+
exports.stringifyWithFormatting = stringifyWithFormatting;
|
|
223
|
+
exports.stripFormattingSymbols = stripFormattingSymbols;
|
package/dist/json/parse.js
CHANGED
|
@@ -1,121 +1,218 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* Socket Lib - Built with
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var import_json = require("../primordials/json");
|
|
35
|
-
var import_map_set = require("../primordials/map-set");
|
|
36
|
-
// @__NO_SIDE_EFFECTS__
|
|
2
|
+
/* Socket Lib - Built with rolldown */
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_primordials_buffer = require('../primordials/buffer.js');
|
|
5
|
+
const require_primordials_error = require('../primordials/error.js');
|
|
6
|
+
const require_primordials_map_set = require('../primordials/map-set.js');
|
|
7
|
+
const require_schema_validate = require('../schema/validate.js');
|
|
8
|
+
const require_strings_transform = require('../strings/transform.js');
|
|
9
|
+
const require_primordials_json = require('../primordials/json.js');
|
|
10
|
+
|
|
11
|
+
//#region src/json/parse.ts
|
|
12
|
+
/**
|
|
13
|
+
* @file JSON parsing utilities with Buffer detection and BOM stripping.
|
|
14
|
+
* Provides safe JSON parsing with automatic encoding handling, plus
|
|
15
|
+
* `parseJsonSafe` for untrusted input (prototype-pollution protection + size
|
|
16
|
+
* limits + optional schema validation).
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Check if a value is a Buffer instance. Uses duck-typing to detect Buffer
|
|
20
|
+
* without requiring Node.js Buffer in type system.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ;```ts
|
|
24
|
+
* isBuffer(Buffer.from('hello')) // => true
|
|
25
|
+
* isBuffer('hello') // => false
|
|
26
|
+
* isBuffer({ length: 5 }) // => false
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param x - Value to check.
|
|
30
|
+
*
|
|
31
|
+
* @returns `true` if value is a Buffer, `false` otherwise
|
|
32
|
+
*/
|
|
33
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
37
34
|
function isBuffer(x) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (typeof obj["copy"] !== "function" || typeof obj["slice"] !== "function") {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
if (typeof obj["length"] === "number" && obj["length"] > 0 && typeof obj[0] !== "number") {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
const Ctor = x.constructor;
|
|
52
|
-
return !!(typeof Ctor?.isBuffer === "function" && Ctor.isBuffer(x));
|
|
35
|
+
if (!x || typeof x !== "object") return false;
|
|
36
|
+
const obj = x;
|
|
37
|
+
if (typeof obj["length"] !== "number") return false;
|
|
38
|
+
if (typeof obj["copy"] !== "function" || typeof obj["slice"] !== "function") return false;
|
|
39
|
+
if (typeof obj["length"] === "number" && obj["length"] > 0 && typeof obj[0] !== "number") return false;
|
|
40
|
+
const Ctor = x.constructor;
|
|
41
|
+
return !!(typeof Ctor?.isBuffer === "function" && Ctor.isBuffer(x));
|
|
53
42
|
}
|
|
54
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Check if a value is a JSON primitive type. JSON primitives are: `null`,
|
|
45
|
+
* `boolean`, `number`, or `string`.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ;```ts
|
|
49
|
+
* isJsonPrimitive(null) // => true
|
|
50
|
+
* isJsonPrimitive(true) // => true
|
|
51
|
+
* isJsonPrimitive(42) // => true
|
|
52
|
+
* isJsonPrimitive('hello') // => true
|
|
53
|
+
* isJsonPrimitive({}) // => false
|
|
54
|
+
* isJsonPrimitive([]) // => false
|
|
55
|
+
* isJsonPrimitive(undefined) // => false
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @param value - Value to check.
|
|
59
|
+
*
|
|
60
|
+
* @returns `true` if value is a JSON primitive, `false` otherwise
|
|
61
|
+
*/
|
|
62
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
55
63
|
function isJsonPrimitive(value) {
|
|
56
|
-
|
|
64
|
+
return value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string";
|
|
57
65
|
}
|
|
58
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Parse JSON content with automatic Buffer handling and BOM stripping. Provides
|
|
68
|
+
* safer JSON parsing with helpful error messages and optional error
|
|
69
|
+
* suppression.
|
|
70
|
+
*
|
|
71
|
+
* Features: - Automatic UTF-8 Buffer conversion - BOM (Byte Order Mark)
|
|
72
|
+
* stripping for cross-platform compatibility - Enhanced error messages with
|
|
73
|
+
* filepath context - Optional error suppression (returns `undefined` instead of
|
|
74
|
+
* throwing) - Optional reviver for transforming parsed values.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ;```ts
|
|
78
|
+
* // Basic usage
|
|
79
|
+
* const data = parseJson('{"name":"example"}')
|
|
80
|
+
* console.log(data.name) // => 'example'
|
|
81
|
+
*
|
|
82
|
+
* // Parse Buffer with UTF-8 BOM
|
|
83
|
+
* const buffer = Buffer.from('\uFEFF{"value":42}')
|
|
84
|
+
* const data = parseJson(buffer)
|
|
85
|
+
* console.log(data.value) // => 42
|
|
86
|
+
*
|
|
87
|
+
* // Enhanced error messages with filepath
|
|
88
|
+
* try {
|
|
89
|
+
* parseJson('invalid', { filepath: 'config.json' })
|
|
90
|
+
* } catch (e) {
|
|
91
|
+
* console.error(e.message)
|
|
92
|
+
* // => "config.json: Unexpected token i in JSON at position 0"
|
|
93
|
+
* }
|
|
94
|
+
*
|
|
95
|
+
* // Suppress errors
|
|
96
|
+
* const result = parseJson('invalid', { throws: false })
|
|
97
|
+
* console.log(result) // => undefined
|
|
98
|
+
*
|
|
99
|
+
* // Transform values with reviver
|
|
100
|
+
* const json = '{"created":"2024-01-15T10:30:00Z"}'
|
|
101
|
+
* const data = parseJson(json, {
|
|
102
|
+
* reviver: (key, value) => {
|
|
103
|
+
* if (key === 'created' && typeof value === 'string') {
|
|
104
|
+
* return new Date(value)
|
|
105
|
+
* }
|
|
106
|
+
* return value
|
|
107
|
+
* },
|
|
108
|
+
* })
|
|
109
|
+
* console.log(data.created instanceof Date) // => true
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @param content - JSON string or Buffer to parse.
|
|
113
|
+
* @param options - Optional parsing configuration.
|
|
114
|
+
*
|
|
115
|
+
* @returns Parsed JSON value, or `undefined` if parsing fails and `throws` is
|
|
116
|
+
* `false`
|
|
117
|
+
*
|
|
118
|
+
* @throws {SyntaxError} When JSON is invalid and `throws` is `true` (default)
|
|
119
|
+
*/
|
|
120
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
59
121
|
function parseJson(content, options) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return void 0;
|
|
122
|
+
const { filepath, reviver, throws } = {
|
|
123
|
+
__proto__: null,
|
|
124
|
+
...options
|
|
125
|
+
};
|
|
126
|
+
const shouldThrow = throws === void 0 || !!throws;
|
|
127
|
+
const jsonStr = /* @__PURE__ */ isBuffer(content) ? content.toString("utf8") : content;
|
|
128
|
+
try {
|
|
129
|
+
return require_primordials_json.JSONParse(/* @__PURE__ */ require_strings_transform.stripBom(jsonStr), reviver);
|
|
130
|
+
} catch (e) {
|
|
131
|
+
if (shouldThrow) {
|
|
132
|
+
const error = e;
|
|
133
|
+
if (error && typeof filepath === "string") error.message = `${filepath}: ${error.message}`;
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
78
137
|
}
|
|
79
|
-
const DANGEROUS_KEYS = new
|
|
138
|
+
const DANGEROUS_KEYS = new require_primordials_map_set.SetCtor([
|
|
139
|
+
"__proto__",
|
|
140
|
+
"constructor",
|
|
141
|
+
"prototype"
|
|
142
|
+
]);
|
|
80
143
|
const DEFAULT_MAX_SIZE = 10 * 1024 * 1024;
|
|
81
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Safely parse JSON with optional schema validation and security controls.
|
|
146
|
+
* Throws on parse failure, validation failure, or security violation.
|
|
147
|
+
*
|
|
148
|
+
* Recommended for parsing untrusted JSON (user input, network payloads,
|
|
149
|
+
* anything beyond a trust boundary). Layers:
|
|
150
|
+
*
|
|
151
|
+
* 1. Size cap (default 10 MB) prevents memory exhaustion.
|
|
152
|
+
* 2. Prototype-pollution reviver rejects `__proto__` / `constructor` / `prototype`
|
|
153
|
+
* keys at any depth (unless `allowPrototype: true`).
|
|
154
|
+
* 3. Optional Zod-shaped schema validation via
|
|
155
|
+
* `@socketsecurity/lib/schema/validate`.
|
|
156
|
+
*
|
|
157
|
+
* For trusted-source reads (package.json, local config files), prefer
|
|
158
|
+
* `parseJson()` — it offers Buffer/BOM handling and filepath-aware error
|
|
159
|
+
* messages, without the untrusted-input overhead.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ;```ts
|
|
163
|
+
* // Basic parsing with type inference.
|
|
164
|
+
* const data = parseJsonSafe<User>('{"name":"Alice","age":30}')
|
|
165
|
+
*
|
|
166
|
+
* // With schema validation.
|
|
167
|
+
* import { z } from 'zod'
|
|
168
|
+
* const userSchema = z.object({ name: z.string(), age: z.number() })
|
|
169
|
+
* const user = parseJsonSafe('{"name":"Alice","age":30}', userSchema)
|
|
170
|
+
*
|
|
171
|
+
* // With size limit.
|
|
172
|
+
* const data = parseJsonSafe(jsonString, undefined, { maxSize: 1024 })
|
|
173
|
+
*
|
|
174
|
+
* // Allow prototype keys (DANGEROUS — only for trusted sources).
|
|
175
|
+
* const data = parseJsonSafe('{"__proto__":{}}', undefined, {
|
|
176
|
+
* allowPrototype: true,
|
|
177
|
+
* })
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @throws {Error} When `jsonString` exceeds `maxSize`.
|
|
181
|
+
* @throws {Error} When JSON parsing fails.
|
|
182
|
+
* @throws {Error} When prototype-pollution keys are detected (and
|
|
183
|
+
* `allowPrototype` is not `true`).
|
|
184
|
+
* @throws {Error} When schema validation fails.
|
|
185
|
+
*/
|
|
186
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
82
187
|
function parseJsonSafe(jsonString, schema, options = {}) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const result = (0, import_validate.validateSchema)(schema, parsed);
|
|
98
|
-
if (!result.ok) {
|
|
99
|
-
const summary = result.errors.map((e) => `${e.path.join(".") || "(root)"}: ${e.message}`).join(", ");
|
|
100
|
-
throw new import_error.ErrorCtor(`Validation failed: ${summary}`);
|
|
101
|
-
}
|
|
102
|
-
return result.value;
|
|
103
|
-
}
|
|
104
|
-
return parsed;
|
|
188
|
+
const { allowPrototype = false, maxSize = DEFAULT_MAX_SIZE } = options;
|
|
189
|
+
if (require_primordials_buffer.BufferByteLength(jsonString, "utf8") > maxSize) throw new require_primordials_error.ErrorCtor(`JSON string exceeds maximum size limit${maxSize !== DEFAULT_MAX_SIZE ? ` of ${maxSize} bytes` : ""}`);
|
|
190
|
+
let parsed;
|
|
191
|
+
try {
|
|
192
|
+
parsed = allowPrototype ? require_primordials_json.JSONParse(jsonString) : require_primordials_json.JSONParse(jsonString, prototypePollutionReviver);
|
|
193
|
+
} catch (e) {
|
|
194
|
+
throw new require_primordials_error.ErrorCtor(`Failed to parse JSON: ${e}`);
|
|
195
|
+
}
|
|
196
|
+
if (schema) {
|
|
197
|
+
const result = require_schema_validate.validateSchema(schema, parsed);
|
|
198
|
+
if (!result.ok) throw new require_primordials_error.ErrorCtor(`Validation failed: ${result.errors.map((e) => `${e.path.join(".") || "(root)"}: ${e.message}`).join(", ")}`);
|
|
199
|
+
return result.value;
|
|
200
|
+
}
|
|
201
|
+
return parsed;
|
|
105
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* JSON.parse reviver that rejects prototype pollution keys at any depth.
|
|
205
|
+
*
|
|
206
|
+
* @internal
|
|
207
|
+
*/
|
|
106
208
|
function prototypePollutionReviver(key, value) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
"JSON contains potentially malicious prototype pollution keys"
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
return value;
|
|
209
|
+
if (DANGEROUS_KEYS.has(key)) throw new require_primordials_error.ErrorCtor("JSON contains potentially malicious prototype pollution keys");
|
|
210
|
+
return value;
|
|
113
211
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
});
|
|
212
|
+
|
|
213
|
+
//#endregion
|
|
214
|
+
exports.isBuffer = isBuffer;
|
|
215
|
+
exports.isJsonPrimitive = isJsonPrimitive;
|
|
216
|
+
exports.parseJson = parseJson;
|
|
217
|
+
exports.parseJsonSafe = parseJsonSafe;
|
|
218
|
+
exports.prototypePollutionReviver = prototypePollutionReviver;
|