structured-outputs 0.1.0-beta.2 → 0.1.0-beta.20
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +77 -6
- package/esm/ResponseFormat.js +33 -5
- package/esm/ResponseFormat.js.map +1 -1
- package/esm/Tool.js +17 -0
- package/esm/Tool.js.map +1 -0
- package/esm/_dnt.polyfills.js +16 -0
- package/esm/_dnt.polyfills.js.map +1 -0
- package/esm/_dnt.shims.js +58 -0
- package/esm/_dnt.shims.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/almost_equals.js +47 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/almost_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/array_includes.js +47 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/array_includes.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assert.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assert.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assertion_error.js +31 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assertion_error.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equal.js +184 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equals.js +46 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/exists.js +28 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/exists.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/fail.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/fail.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/false.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/false.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/instance_of.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/instance_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/is_error.js +54 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/is_error.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less_or_equal.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less_or_equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/match.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/mod.js +46 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/mod.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_equals.js +33 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_instance_of.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_instance_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_match.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.js +33 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/object_match.js +160 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/object_match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/rejects.js +54 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/rejects.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/strict_equals.js +58 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/strict_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/string_includes.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/string_includes.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/throws.js +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/throws.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unimplemented.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unimplemented.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unreachable.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unreachable.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/_utils.js +19 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/_utils.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.js +51 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_by.js +45 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_with.js +41 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_with.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/chunk.js +51 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/chunk.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/deep_merge.js +96 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/deep_merge.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct.js +28 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct_by.js +39 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_last_while.js +33 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_last_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_while.js +34 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_entries.js +43 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_entries.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_keys.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_keys.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_values.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_values.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/find_single.js +45 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/find_single.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.js +42 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/includes_value.js +39 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/includes_value.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/intersect.js +36 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/intersect.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert.js +29 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert_by.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/join_to_string.js +59 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/join_to_string.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_entries.js +47 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_entries.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_keys.js +42 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_keys.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.js +43 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_values.js +13 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_values.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_by.js +15 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_of.js +17 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_with.js +41 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_with.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_by.js +15 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_of.js +17 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_with.js +37 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_with.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/mod.js +75 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/mod.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/omit.js +29 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/omit.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition.js +16 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition_entries.js +54 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition_entries.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/permutations.js +58 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/permutations.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/pick.js +33 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/pick.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/reduce_groups.js +40 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/reduce_groups.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/running_reduce.js +32 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/running_reduce.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sample.js +35 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sample.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sliding_windows.js +57 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sliding_windows.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sort_by.js +30 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sort_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sum_of.js +37 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sum_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_last_while.js +34 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_last_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_while.js +39 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/union.js +34 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/union.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/unzip.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/unzip.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/without_all.js +28 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/without_all.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/zip.js +43 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/zip.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.js +111 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff.js +277 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.js +180 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/format.js +38 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/format.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/styles.js +208 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/styles.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/types.js +3 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/types.js.map +1 -0
- package/esm/mod.js +3 -10
- package/esm/mod.js.map +1 -1
- package/esm/types/Ref.js +11 -0
- package/esm/types/Ref.js.map +1 -0
- package/esm/types/RootTy.js +19 -0
- package/esm/types/RootTy.js.map +1 -0
- package/esm/types/Ty.js +17 -0
- package/esm/types/Ty.js.map +1 -0
- package/esm/types/array.js +9 -0
- package/esm/types/array.js.map +1 -0
- package/esm/types/constant.js +8 -0
- package/esm/types/constant.js.map +1 -0
- package/esm/types/constantUnion.js +25 -0
- package/esm/types/constantUnion.js.map +1 -0
- package/esm/types/leaves.js +18 -0
- package/esm/types/leaves.js.map +1 -0
- package/esm/types/mod.js +11 -0
- package/esm/types/mod.js.map +1 -0
- package/esm/{object.js → types/object.js} +4 -4
- package/esm/types/object.js.map +1 -0
- package/esm/types/std/Option.js +9 -0
- package/esm/types/std/Option.js.map +1 -0
- package/esm/types/std/Wrapper.js +5 -0
- package/esm/types/std/Wrapper.js.map +1 -0
- package/esm/types/std/mod.js +3 -0
- package/esm/types/std/mod.js.map +1 -0
- package/esm/types/taggedUnion.js +20 -0
- package/esm/types/taggedUnion.js.map +1 -0
- package/esm/util/phantoms.js +4 -0
- package/esm/util/phantoms.js.map +1 -0
- package/esm/util/recombineTaggedTemplateArgs.js +4 -0
- package/esm/util/recombineTaggedTemplateArgs.js.map +1 -0
- package/package.json +10 -7
- package/src/ResponseFormat.ts +76 -25
- package/src/Tool.ts +38 -0
- package/src/_dnt.polyfills.ts +27 -0
- package/src/_dnt.shims.ts +60 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/almost_equals.ts +55 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/array_includes.ts +57 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/assert.ts +23 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/assertion_error.ts +31 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/equal.ts +210 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/equals.ts +52 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/exists.ts +31 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/fail.ts +21 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/false.ts +26 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/greater.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/instance_of.ts +64 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/is_error.ts +65 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/less.ts +29 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/less_or_equal.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/match.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/mod.ts +47 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_equals.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_instance_of.ts +33 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_match.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.ts +42 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/object_match.ts +202 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/rejects.ts +123 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/strict_equals.ts +67 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/string_includes.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/throws.ts +111 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/unimplemented.ts +21 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/unreachable.ts +21 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/_utils.ts +26 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.ts +62 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/associate_by.ts +50 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/associate_with.ts +46 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/chunk.ts +56 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/deep_merge.ts +578 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/distinct.ts +29 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/distinct_by.ts +42 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/drop_last_while.ts +36 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/drop_while.ts +39 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/filter_entries.ts +48 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/filter_keys.ts +51 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/filter_values.ts +51 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/find_single.ts +48 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.ts +47 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/includes_value.ts +45 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/intersect.ts +35 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/invert.ts +38 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/invert_by.ts +56 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/join_to_string.ts +109 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_entries.ts +53 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_keys.ts +47 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.ts +49 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_values.ts +96 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/max_by.ts +153 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/max_of.ts +90 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/max_with.ts +46 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/min_by.ts +151 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/min_of.ts +90 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/min_with.ts +42 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/mod.ts +76 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/omit.ts +34 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/partition.ts +85 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/partition_entries.ts +58 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/permutations.ts +66 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/pick.ts +34 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/reduce_groups.ts +45 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/running_reduce.ts +38 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sample.ts +36 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sliding_windows.ts +86 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sort_by.ts +219 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sum_of.ts +42 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/take_last_while.ts +37 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/take_while.ts +44 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/union.ts +36 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/unzip.ts +50 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/without_all.ts +28 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/zip.ts +49 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/build_message.ts +134 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/diff.ts +317 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/diff_str.ts +204 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/format.ts +39 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/styles.ts +233 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/types.ts +18 -0
- package/src/mod.ts +3 -18
- package/src/types/Ref.ts +16 -0
- package/src/types/RootTy.ts +40 -0
- package/src/types/Ty.ts +57 -0
- package/src/types/array.ts +9 -0
- package/src/types/constant.ts +8 -0
- package/src/types/constantUnion.ts +27 -0
- package/src/types/leaves.ts +21 -0
- package/src/types/mod.ts +10 -0
- package/src/types/object.ts +15 -0
- package/src/types/std/Option.ts +15 -0
- package/src/types/std/Wrapper.ts +8 -0
- package/src/types/std/mod.ts +2 -0
- package/src/types/taggedUnion.ts +28 -0
- package/src/util/phantoms.ts +3 -0
- package/src/util/recombineTaggedTemplateArgs.ts +6 -0
- package/types/ResponseFormat.d.ts +26 -0
- package/types/ResponseFormat.d.ts.map +1 -0
- package/types/Tool.d.ts +13 -0
- package/types/Tool.d.ts.map +1 -0
- package/types/_dnt.polyfills.d.ts +12 -0
- package/types/_dnt.polyfills.d.ts.map +1 -0
- package/types/_dnt.shims.d.ts +2 -0
- package/types/_dnt.shims.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/almost_equals.d.ts +29 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/almost_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/array_includes.d.ts +24 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/array_includes.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assert.d.ts +16 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assert.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assertion_error.d.ts +26 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assertion_error.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equal.d.ts +17 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equal.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equals.d.ts +22 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/exists.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/exists.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/fail.d.ts +15 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/fail.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/false.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/false.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/instance_of.d.ts +23 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/instance_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/is_error.d.ts +25 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/is_error.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less.d.ts +19 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less_or_equal.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less_or_equal.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/match.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/match.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/mod.d.ts +44 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/mod.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_equals.d.ts +21 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_instance_of.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_instance_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_match.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_match.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.d.ts +23 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/object_match.d.ts +28 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/object_match.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/rejects.d.ts +42 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/rejects.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/strict_equals.d.ts +24 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/strict_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/string_includes.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/string_includes.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/throws.d.ts +45 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/throws.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unimplemented.d.ts +15 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unimplemented.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unreachable.d.ts +15 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unreachable.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/_utils.d.ts +6 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/_utils.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.d.ts +41 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_by.d.ts +37 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_with.d.ts +33 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_with.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/chunk.d.ts +38 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/chunk.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/deep_merge.d.ts +322 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/deep_merge.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct.d.ts +23 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct_by.d.ts +26 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_last_while.d.ts +26 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_last_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_while.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_entries.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_entries.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_keys.d.ts +36 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_keys.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_values.d.ts +35 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_values.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/find_single.d.ts +31 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/find_single.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/includes_value.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/includes_value.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/intersect.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/intersect.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert_by.d.ts +34 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/join_to_string.d.ts +75 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/join_to_string.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_entries.d.ts +37 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_entries.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_keys.d.ts +33 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_keys.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_values.d.ts +71 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_values.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_by.d.ts +117 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_of.d.ts +61 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_with.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_with.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_by.d.ts +115 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_of.d.ts +61 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_with.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_with.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/mod.d.ts +73 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/mod.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/omit.d.ts +24 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/omit.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition.d.ts +60 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition_entries.d.ts +39 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition_entries.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/permutations.d.ts +27 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/permutations.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/pick.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/pick.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/reduce_groups.d.ts +35 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/reduce_groups.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/running_reduce.d.ts +27 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/running_reduce.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sample.d.ts +24 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sample.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sliding_windows.d.ts +66 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sliding_windows.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sort_by.d.ts +161 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sort_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sum_of.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sum_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_last_while.d.ts +27 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_last_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_while.d.ts +30 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/union.d.ts +24 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/union.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/unzip.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/unzip.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/without_all.d.ts +23 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/without_all.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/zip.d.ts +34 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/zip.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts +82 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff.d.ts +140 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts +99 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/format.d.ts +2 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/format.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/styles.d.ts +159 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/styles.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/types.d.ts +16 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/types.d.ts.map +1 -0
- package/types/mod.d.ts +5 -0
- package/types/mod.d.ts.map +1 -0
- package/types/types/Ref.d.ts +4 -0
- package/types/types/Ref.d.ts.map +1 -0
- package/types/types/RootTy.d.ts +8 -0
- package/types/types/RootTy.d.ts.map +1 -0
- package/types/types/Ty.d.ts +27 -0
- package/types/types/Ty.d.ts.map +1 -0
- package/types/types/array.d.ts +3 -0
- package/types/types/array.d.ts.map +1 -0
- package/types/types/constant.d.ts +3 -0
- package/types/types/constant.d.ts.map +1 -0
- package/types/types/constantUnion.d.ts +3 -0
- package/types/types/constantUnion.d.ts.map +1 -0
- package/types/types/leaves.d.ts +6 -0
- package/types/types/leaves.d.ts.map +1 -0
- package/types/types/mod.d.ts +11 -0
- package/types/types/mod.d.ts.map +1 -0
- package/types/types/object.d.ts +6 -0
- package/types/types/object.d.ts.map +1 -0
- package/types/types/std/Option.d.ts +7 -0
- package/types/types/std/Option.d.ts.map +1 -0
- package/types/types/std/Wrapper.d.ts +7 -0
- package/types/types/std/Wrapper.d.ts.map +1 -0
- package/types/types/std/mod.d.ts +3 -0
- package/types/types/std/mod.d.ts.map +1 -0
- package/types/types/taggedUnion.d.ts +8 -0
- package/types/types/taggedUnion.d.ts.map +1 -0
- package/types/util/phantoms.d.ts +2 -0
- package/types/util/phantoms.d.ts.map +1 -0
- package/types/util/recombineTaggedTemplateArgs.d.ts +2 -0
- package/types/util/recombineTaggedTemplateArgs.d.ts.map +1 -0
- package/esm/F.d.ts +0 -13
- package/esm/F.d.ts.map +0 -1
- package/esm/F.js +0 -10
- package/esm/F.js.map +0 -1
- package/esm/ResponseFormat.d.ts +0 -14
- package/esm/ResponseFormat.d.ts.map +0 -1
- package/esm/_base.d.ts +0 -13
- package/esm/_base.d.ts.map +0 -1
- package/esm/_base.js +0 -40
- package/esm/_base.js.map +0 -1
- package/esm/array.d.ts +0 -4
- package/esm/array.d.ts.map +0 -1
- package/esm/array.js +0 -9
- package/esm/array.js.map +0 -1
- package/esm/common.d.ts +0 -6
- package/esm/common.d.ts.map +0 -1
- package/esm/common.js +0 -2
- package/esm/common.js.map +0 -1
- package/esm/literal.d.ts +0 -4
- package/esm/literal.d.ts.map +0 -1
- package/esm/literal.js +0 -8
- package/esm/literal.js.map +0 -1
- package/esm/mod.d.ts +0 -16
- package/esm/mod.d.ts.map +0 -1
- package/esm/number.d.ts +0 -4
- package/esm/number.d.ts.map +0 -1
- package/esm/number.js +0 -8
- package/esm/number.js.map +0 -1
- package/esm/object.d.ts +0 -7
- package/esm/object.d.ts.map +0 -1
- package/esm/object.js.map +0 -1
- package/esm/schema.d.ts +0 -4
- package/esm/schema.d.ts.map +0 -1
- package/esm/schema.js +0 -9
- package/esm/schema.js.map +0 -1
- package/esm/string.d.ts +0 -4
- package/esm/string.d.ts.map +0 -1
- package/esm/string.js +0 -8
- package/esm/string.js.map +0 -1
- package/esm/union.d.ts +0 -6
- package/esm/union.d.ts.map +0 -1
- package/esm/union.js +0 -8
- package/esm/union.js.map +0 -1
- package/src/F.ts +0 -27
- package/src/_base.ts +0 -25
- package/src/array.ts +0 -11
- package/src/common.ts +0 -6
- package/src/literal.ts +0 -10
- package/src/number.ts +0 -10
- package/src/object.ts +0 -17
- package/src/schema.ts +0 -10
- package/src/string.ts +0 -10
- package/src/union.ts +0 -12
@@ -0,0 +1,219 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
|
4
|
+
/** Order option for {@linkcode SortByOptions}. */
|
5
|
+
export type Order = "asc" | "desc";
|
6
|
+
|
7
|
+
/** Options for {@linkcode sortBy}. */
|
8
|
+
export type SortByOptions = {
|
9
|
+
/**
|
10
|
+
* The order to sort the elements in.
|
11
|
+
*
|
12
|
+
* @default {"asc"}
|
13
|
+
*/
|
14
|
+
order: Order;
|
15
|
+
};
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Returns all elements in the given collection, sorted by their result using
|
19
|
+
* the given selector. The selector function is called only once for each
|
20
|
+
* element. Ascending or descending order can be specified through the `order`
|
21
|
+
* option. By default, the elements are sorted in ascending order.
|
22
|
+
*
|
23
|
+
* Note: If you want to process any iterable, use the new version of
|
24
|
+
* `sortBy` from `@std/collections/unstable-sort-by`.
|
25
|
+
*
|
26
|
+
* @typeParam T The type of the array elements.
|
27
|
+
*
|
28
|
+
* @param array The array to sort.
|
29
|
+
* @param selector The selector function to get the value to sort by.
|
30
|
+
* @param options The options for sorting.
|
31
|
+
*
|
32
|
+
* @returns A new array containing all elements sorted by the selector.
|
33
|
+
*
|
34
|
+
* @example Usage
|
35
|
+
* ```ts
|
36
|
+
* import { sortBy } from "@std/collections/sort-by";
|
37
|
+
* import { assertEquals } from "@std/assert";
|
38
|
+
*
|
39
|
+
* const people = [
|
40
|
+
* { name: "Anna", age: 34 },
|
41
|
+
* { name: "Kim", age: 42 },
|
42
|
+
* { name: "John", age: 23 },
|
43
|
+
* ];
|
44
|
+
* const sortedByAge = sortBy(people, (person) => person.age);
|
45
|
+
*
|
46
|
+
* assertEquals(sortedByAge, [
|
47
|
+
* { name: "John", age: 23 },
|
48
|
+
* { name: "Anna", age: 34 },
|
49
|
+
* { name: "Kim", age: 42 },
|
50
|
+
* ]);
|
51
|
+
*
|
52
|
+
* const sortedByAgeDesc = sortBy(people, (person) => person.age, { order: "desc" });
|
53
|
+
*
|
54
|
+
* assertEquals(sortedByAgeDesc, [
|
55
|
+
* { name: "Kim", age: 42 },
|
56
|
+
* { name: "Anna", age: 34 },
|
57
|
+
* { name: "John", age: 23 },
|
58
|
+
* ]);
|
59
|
+
* ```
|
60
|
+
*/
|
61
|
+
export function sortBy<T>(
|
62
|
+
array: readonly T[],
|
63
|
+
selector: (el: T) => number,
|
64
|
+
options?: SortByOptions,
|
65
|
+
): T[];
|
66
|
+
/**
|
67
|
+
* Returns all elements in the given collection, sorted by their result using
|
68
|
+
* the given selector. The selector function is called only once for each
|
69
|
+
* element. Ascending or descending order can be specified through the `order`
|
70
|
+
* option. By default, the elements are sorted in ascending order.
|
71
|
+
*
|
72
|
+
* @typeParam T The type of the array elements.
|
73
|
+
*
|
74
|
+
* @param array The array to sort.
|
75
|
+
* @param selector The selector function to get the value to sort by.
|
76
|
+
* @param options The options for sorting.
|
77
|
+
*
|
78
|
+
* @returns A new array containing all elements sorted by the selector.
|
79
|
+
*
|
80
|
+
* @example Usage
|
81
|
+
* ```ts
|
82
|
+
* import { sortBy } from "@std/collections/sort-by";
|
83
|
+
* import { assertEquals } from "@std/assert";
|
84
|
+
*
|
85
|
+
* const people = [
|
86
|
+
* { name: "Anna" },
|
87
|
+
* { name: "Kim" },
|
88
|
+
* { name: "John" },
|
89
|
+
* ];
|
90
|
+
* const sortedByName = sortBy(people, (it) => it.name);
|
91
|
+
*
|
92
|
+
* assertEquals(sortedByName, [
|
93
|
+
* { name: "Anna" },
|
94
|
+
* { name: "John" },
|
95
|
+
* { name: "Kim" },
|
96
|
+
* ]);
|
97
|
+
* ```
|
98
|
+
*/
|
99
|
+
export function sortBy<T>(
|
100
|
+
array: readonly T[],
|
101
|
+
selector: (el: T) => string,
|
102
|
+
options?: SortByOptions,
|
103
|
+
): T[];
|
104
|
+
/**
|
105
|
+
* Returns all elements in the given collection, sorted by their result using
|
106
|
+
* the given selector. The selector function is called only once for each
|
107
|
+
* element. Ascending or descending order can be specified through the `order`
|
108
|
+
* option. By default, the elements are sorted in ascending order.
|
109
|
+
*
|
110
|
+
* @typeParam T The type of the array elements.
|
111
|
+
*
|
112
|
+
* @param array The array to sort.
|
113
|
+
* @param selector The selector function to get the value to sort by.
|
114
|
+
* @param options The options for sorting.
|
115
|
+
*
|
116
|
+
* @returns A new array containing all elements sorted by the selector.
|
117
|
+
*
|
118
|
+
* @example Usage
|
119
|
+
* ```ts
|
120
|
+
* import { sortBy } from "@std/collections/sort-by";
|
121
|
+
* import { assertEquals } from "@std/assert";
|
122
|
+
*
|
123
|
+
* const people = [
|
124
|
+
* { name: "Anna", age: 34n },
|
125
|
+
* { name: "Kim", age: 42n },
|
126
|
+
* { name: "John", age: 23n },
|
127
|
+
* ];
|
128
|
+
*
|
129
|
+
* const sortedByAge = sortBy(people, (person) => person.age);
|
130
|
+
*
|
131
|
+
* assertEquals(sortedByAge, [
|
132
|
+
* { name: "John", age: 23n },
|
133
|
+
* { name: "Anna", age: 34n },
|
134
|
+
* { name: "Kim", age: 42n },
|
135
|
+
* ]);
|
136
|
+
* ```
|
137
|
+
*/
|
138
|
+
|
139
|
+
export function sortBy<T>(
|
140
|
+
array: readonly T[],
|
141
|
+
selector: (el: T) => bigint,
|
142
|
+
options?: SortByOptions,
|
143
|
+
): T[];
|
144
|
+
/**
|
145
|
+
* Returns all elements in the given collection, sorted by their result using
|
146
|
+
* the given selector. The selector function is called only once for each
|
147
|
+
* element. Ascending or descending order can be specified through the `order`
|
148
|
+
* option. By default, the elements are sorted in ascending order.
|
149
|
+
*
|
150
|
+
* @typeParam T The type of the array elements.
|
151
|
+
*
|
152
|
+
* @param array The array to sort.
|
153
|
+
* @param selector The selector function to get the value to sort by.
|
154
|
+
* @param options The options for sorting.
|
155
|
+
*
|
156
|
+
* @returns A new array containing all elements sorted by the selector.
|
157
|
+
*
|
158
|
+
* @example Usage
|
159
|
+
* ```ts
|
160
|
+
* import { sortBy } from "@std/collections/sort-by";
|
161
|
+
* import { assertEquals } from "@std/assert";
|
162
|
+
*
|
163
|
+
* const people = [
|
164
|
+
* { name: "Anna", startedAt: new Date("2020-01-01") },
|
165
|
+
* { name: "Kim", startedAt: new Date("2020-03-01") },
|
166
|
+
* { name: "John", startedAt: new Date("2020-06-01") },
|
167
|
+
* ];
|
168
|
+
*
|
169
|
+
* const sortedByStartedAt = sortBy(people, (people) => people.startedAt);
|
170
|
+
*
|
171
|
+
* assertEquals(sortedByStartedAt, [
|
172
|
+
* { name: "Anna", startedAt: new Date("2020-01-01") },
|
173
|
+
* { name: "Kim", startedAt: new Date("2020-03-01") },
|
174
|
+
* { name: "John", startedAt: new Date("2020-06-01") },
|
175
|
+
* ]);
|
176
|
+
* ```
|
177
|
+
*/
|
178
|
+
export function sortBy<T>(
|
179
|
+
array: readonly T[],
|
180
|
+
selector: (el: T) => Date,
|
181
|
+
options?: SortByOptions,
|
182
|
+
): T[];
|
183
|
+
export function sortBy<T>(
|
184
|
+
array: readonly T[],
|
185
|
+
selector:
|
186
|
+
| ((el: T) => number)
|
187
|
+
| ((el: T) => string)
|
188
|
+
| ((el: T) => bigint)
|
189
|
+
| ((el: T) => Date),
|
190
|
+
options?: SortByOptions,
|
191
|
+
): T[] {
|
192
|
+
const len = array.length;
|
193
|
+
const indexes = new Array<number>(len);
|
194
|
+
const selectors = new Array<ReturnType<typeof selector> | null>(len);
|
195
|
+
const order = options?.order ?? "asc";
|
196
|
+
|
197
|
+
array.forEach((element, index) => {
|
198
|
+
indexes[index] = index;
|
199
|
+
const selected = selector(element);
|
200
|
+
selectors[index] = Number.isNaN(selected) ? null : selected;
|
201
|
+
});
|
202
|
+
|
203
|
+
indexes.sort((ai, bi) => {
|
204
|
+
let a = selectors[ai]!;
|
205
|
+
let b = selectors[bi]!;
|
206
|
+
if (order === "desc") {
|
207
|
+
[a, b] = [b, a];
|
208
|
+
}
|
209
|
+
if (a === null) return 1;
|
210
|
+
if (b === null) return -1;
|
211
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
212
|
+
});
|
213
|
+
|
214
|
+
for (let i = 0; i < len; i++) {
|
215
|
+
(indexes as unknown as T[])[i] = array[indexes[i]!] as T;
|
216
|
+
}
|
217
|
+
|
218
|
+
return indexes as unknown as T[];
|
219
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Applies the given selector to all elements in the given collection and
|
6
|
+
* calculates the sum of the results.
|
7
|
+
*
|
8
|
+
* @typeParam T The type of the array elements.
|
9
|
+
*
|
10
|
+
* @param array The array to calculate the sum of.
|
11
|
+
* @param selector The selector function to get the value to sum.
|
12
|
+
*
|
13
|
+
* @returns The sum of all elements in the collection.
|
14
|
+
*
|
15
|
+
* @example Basic usage
|
16
|
+
* ```ts
|
17
|
+
* import { sumOf } from "@std/collections/sum-of";
|
18
|
+
* import { assertEquals } from "@std/assert";
|
19
|
+
*
|
20
|
+
* const people = [
|
21
|
+
* { name: "Anna", age: 34 },
|
22
|
+
* { name: "Kim", age: 42 },
|
23
|
+
* { name: "John", age: 23 },
|
24
|
+
* ];
|
25
|
+
*
|
26
|
+
* const totalAge = sumOf(people, (person) => person.age);
|
27
|
+
*
|
28
|
+
* assertEquals(totalAge, 99);
|
29
|
+
* ```
|
30
|
+
*/
|
31
|
+
export function sumOf<T>(
|
32
|
+
array: Iterable<T>,
|
33
|
+
selector: (el: T) => number,
|
34
|
+
): number {
|
35
|
+
let sum = 0;
|
36
|
+
|
37
|
+
for (const i of array) {
|
38
|
+
sum += selector(i);
|
39
|
+
}
|
40
|
+
|
41
|
+
return sum;
|
42
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Returns all elements in the given array after the last element that does not
|
6
|
+
* match the given predicate.
|
7
|
+
*
|
8
|
+
* @typeParam T The type of the array elements.
|
9
|
+
*
|
10
|
+
* @param array The array to take elements from.
|
11
|
+
* @param predicate The predicate function to determine if an element should be
|
12
|
+
* included.
|
13
|
+
*
|
14
|
+
* @returns A new array containing all elements after the last element that does
|
15
|
+
* not match the predicate.
|
16
|
+
*
|
17
|
+
* @example Basic usage
|
18
|
+
* ```ts
|
19
|
+
* import { takeLastWhile } from "@std/collections/take-last-while";
|
20
|
+
* import { assertEquals } from "@std/assert";
|
21
|
+
*
|
22
|
+
* const numbers = [1, 2, 3, 4, 5, 6];
|
23
|
+
*
|
24
|
+
* const result = takeLastWhile(numbers, (number) => number > 4);
|
25
|
+
*
|
26
|
+
* assertEquals(result, [5, 6]);
|
27
|
+
* ```
|
28
|
+
*/
|
29
|
+
export function takeLastWhile<T>(
|
30
|
+
array: readonly T[],
|
31
|
+
predicate: (el: T) => boolean,
|
32
|
+
): T[] {
|
33
|
+
let offset = array.length;
|
34
|
+
while (0 < offset && predicate(array[offset - 1] as T)) offset--;
|
35
|
+
|
36
|
+
return array.slice(offset, array.length);
|
37
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Returns all elements in the given collection until the first element that
|
6
|
+
* does not match the given predicate.
|
7
|
+
*
|
8
|
+
* Note: If you want to process any iterable, use the new version of
|
9
|
+
* `takeWhile` from `@std/collections/unstable-take-while`.
|
10
|
+
*
|
11
|
+
* @typeParam T The type of the array elements.
|
12
|
+
*
|
13
|
+
* @param array The array to take elements from.
|
14
|
+
* @param predicate The predicate function to determine if an element should be
|
15
|
+
* included.
|
16
|
+
*
|
17
|
+
* @returns A new array containing all elements until the first element that
|
18
|
+
* does not match the predicate.
|
19
|
+
*
|
20
|
+
* @example Basic usage
|
21
|
+
* ```ts
|
22
|
+
* import { takeWhile } from "@std/collections/take-while";
|
23
|
+
* import { assertEquals } from "@std/assert";
|
24
|
+
*
|
25
|
+
* const numbers = [1, 2, 3, 4, 5, 6];
|
26
|
+
*
|
27
|
+
* const result = takeWhile(numbers, (number) => number < 4);
|
28
|
+
*
|
29
|
+
* assertEquals(result, [1, 2, 3]);
|
30
|
+
* ```
|
31
|
+
*/
|
32
|
+
export function takeWhile<T>(
|
33
|
+
array: readonly T[],
|
34
|
+
predicate: (el: T) => boolean,
|
35
|
+
): T[] {
|
36
|
+
let offset = 0;
|
37
|
+
const length = array.length;
|
38
|
+
|
39
|
+
while (length > offset && predicate(array[offset] as T)) {
|
40
|
+
offset++;
|
41
|
+
}
|
42
|
+
|
43
|
+
return array.slice(0, offset);
|
44
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Returns all distinct elements that appear in any of the given arrays.
|
6
|
+
*
|
7
|
+
* @typeParam T The type of the array elements.
|
8
|
+
*
|
9
|
+
* @param arrays The arrays to get the union of.
|
10
|
+
*
|
11
|
+
* @returns A new array containing all distinct elements from the given arrays.
|
12
|
+
*
|
13
|
+
* @example Basic usage
|
14
|
+
* ```ts
|
15
|
+
* import { union } from "@std/collections/union";
|
16
|
+
* import { assertEquals } from "@std/assert";
|
17
|
+
*
|
18
|
+
* const soupIngredients = ["Pepper", "Carrots", "Leek"];
|
19
|
+
* const saladIngredients = ["Carrots", "Radicchio", "Pepper"];
|
20
|
+
*
|
21
|
+
* const shoppingList = union(soupIngredients, saladIngredients);
|
22
|
+
*
|
23
|
+
* assertEquals(shoppingList, ["Pepper", "Carrots", "Leek", "Radicchio"]);
|
24
|
+
* ```
|
25
|
+
*/
|
26
|
+
export function union<T>(...arrays: Iterable<T>[]): T[] {
|
27
|
+
const set = new Set<T>();
|
28
|
+
|
29
|
+
for (const array of arrays) {
|
30
|
+
for (const element of array) {
|
31
|
+
set.add(element);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
return Array.from(set);
|
36
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Builds two separate arrays from the given array of 2-tuples, with the first
|
6
|
+
* returned array holding all first tuple elements and the second one holding
|
7
|
+
* all the second elements.
|
8
|
+
*
|
9
|
+
* @typeParam T The type of the first tuple elements.
|
10
|
+
* @typeParam U The type of the second tuple elements.
|
11
|
+
*
|
12
|
+
* @param pairs The array of 2-tuples to unzip.
|
13
|
+
*
|
14
|
+
* @returns A tuple containing two arrays, the first one holding all first tuple
|
15
|
+
* elements and the second one holding all second elements.
|
16
|
+
*
|
17
|
+
* @example Basic usage
|
18
|
+
* ```ts
|
19
|
+
* import { unzip } from "@std/collections/unzip";
|
20
|
+
* import { assertEquals } from "@std/assert";
|
21
|
+
*
|
22
|
+
* const parents = [
|
23
|
+
* ["Maria", "Jeff"],
|
24
|
+
* ["Anna", "Kim"],
|
25
|
+
* ["John", "Leroy"],
|
26
|
+
* ] as [string, string][];
|
27
|
+
*
|
28
|
+
* const [moms, dads] = unzip(parents);
|
29
|
+
*
|
30
|
+
* assertEquals(moms, ["Maria", "Anna", "John"]);
|
31
|
+
* assertEquals(dads, ["Jeff", "Kim", "Leroy"]);
|
32
|
+
* ```
|
33
|
+
*/
|
34
|
+
export function unzip<T, U>(pairs: readonly [T, U][]): [T[], U[]] {
|
35
|
+
const { length } = pairs;
|
36
|
+
|
37
|
+
const result: [T[], U[]] = [
|
38
|
+
new Array<T>(length),
|
39
|
+
new Array<U>(length),
|
40
|
+
];
|
41
|
+
|
42
|
+
for (let i = 0; i < length; ++i) {
|
43
|
+
const pair = pairs[i] as [T, U];
|
44
|
+
|
45
|
+
result[0][i] = pair[0];
|
46
|
+
result[1][i] = pair[1];
|
47
|
+
}
|
48
|
+
|
49
|
+
return result;
|
50
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Returns an array excluding all given values.
|
6
|
+
*
|
7
|
+
* @typeParam T The type of the array elements.
|
8
|
+
*
|
9
|
+
* @param array The array to exclude values from.
|
10
|
+
* @param values The values to exclude from the array.
|
11
|
+
*
|
12
|
+
* @returns A new array containing all elements from the given array except the
|
13
|
+
* ones that are in the values array.
|
14
|
+
*
|
15
|
+
* @example Basic usage
|
16
|
+
* ```ts
|
17
|
+
* import { withoutAll } from "@std/collections/without-all";
|
18
|
+
* import { assertEquals } from "@std/assert";
|
19
|
+
*
|
20
|
+
* const withoutList = withoutAll([2, 1, 2, 3], [1, 2]);
|
21
|
+
*
|
22
|
+
* assertEquals(withoutList, [3]);
|
23
|
+
* ```
|
24
|
+
*/
|
25
|
+
export function withoutAll<T>(array: readonly T[], values: readonly T[]): T[] {
|
26
|
+
const toExclude = new Set(values);
|
27
|
+
return array.filter((it) => !toExclude.has(it));
|
28
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
|
4
|
+
import { minOf } from "./min_of.js";
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Builds N-tuples of elements from the given N arrays with matching indices,
|
8
|
+
* stopping when the smallest array's end is reached.
|
9
|
+
*
|
10
|
+
* @typeParam T the type of the tuples produced by this function.
|
11
|
+
*
|
12
|
+
* @param arrays The arrays to zip.
|
13
|
+
*
|
14
|
+
* @returns A new array containing N-tuples of elements from the given arrays.
|
15
|
+
*
|
16
|
+
* @example Basic usage
|
17
|
+
* ```ts
|
18
|
+
* import { zip } from "@std/collections/zip";
|
19
|
+
* import { assertEquals } from "@std/assert";
|
20
|
+
*
|
21
|
+
* const numbers = [1, 2, 3, 4];
|
22
|
+
* const letters = ["a", "b", "c", "d"];
|
23
|
+
* const pairs = zip(numbers, letters);
|
24
|
+
*
|
25
|
+
* assertEquals(
|
26
|
+
* pairs,
|
27
|
+
* [
|
28
|
+
* [1, "a"],
|
29
|
+
* [2, "b"],
|
30
|
+
* [3, "c"],
|
31
|
+
* [4, "d"],
|
32
|
+
* ],
|
33
|
+
* );
|
34
|
+
* ```
|
35
|
+
*/
|
36
|
+
export function zip<T extends unknown[]>(
|
37
|
+
...arrays: { [K in keyof T]: ReadonlyArray<T[K]> }
|
38
|
+
): T[] {
|
39
|
+
const minLength = minOf(arrays, (element) => element.length) ?? 0;
|
40
|
+
|
41
|
+
const result: T[] = new Array(minLength);
|
42
|
+
|
43
|
+
for (let i = 0; i < minLength; i += 1) {
|
44
|
+
const arr = arrays.map((it) => it[i]);
|
45
|
+
result[i] = arr as T;
|
46
|
+
}
|
47
|
+
|
48
|
+
return result;
|
49
|
+
}
|
@@ -0,0 +1,134 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
|
4
|
+
import { bgGreen, bgRed, bold, gray, green, red, white } from "./styles.js";
|
5
|
+
import type { DiffResult, DiffType } from "./types.js";
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Colors the output of assertion diffs.
|
9
|
+
*
|
10
|
+
* @param diffType Difference type, either added or removed.
|
11
|
+
* @param background If true, colors the background instead of the text.
|
12
|
+
*
|
13
|
+
* @returns A function that colors the input string.
|
14
|
+
*
|
15
|
+
* @example Usage
|
16
|
+
* ```ts
|
17
|
+
* import { createColor } from "@std/internal";
|
18
|
+
* import { assertEquals } from "@std/assert";
|
19
|
+
* import { bold, green, red, white } from "@std/fmt/colors";
|
20
|
+
*
|
21
|
+
* assertEquals(createColor("added")("foo"), green(bold("foo")));
|
22
|
+
* assertEquals(createColor("removed")("foo"), red(bold("foo")));
|
23
|
+
* assertEquals(createColor("common")("foo"), white("foo"));
|
24
|
+
* ```
|
25
|
+
*/
|
26
|
+
export function createColor(
|
27
|
+
diffType: DiffType,
|
28
|
+
/**
|
29
|
+
* TODO(@littledivy): Remove this when we can detect true color terminals. See
|
30
|
+
* https://github.com/denoland/deno_std/issues/2575.
|
31
|
+
*/
|
32
|
+
background = false,
|
33
|
+
): (s: string) => string {
|
34
|
+
switch (diffType) {
|
35
|
+
case "added":
|
36
|
+
return (s) => background ? bgGreen(white(s)) : green(bold(s));
|
37
|
+
case "removed":
|
38
|
+
return (s) => background ? bgRed(white(s)) : red(bold(s));
|
39
|
+
default:
|
40
|
+
return white;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Prefixes `+` or `-` in diff output.
|
46
|
+
*
|
47
|
+
* @param diffType Difference type, either added or removed
|
48
|
+
*
|
49
|
+
* @returns A string representing the sign.
|
50
|
+
*
|
51
|
+
* @example Usage
|
52
|
+
* ```ts
|
53
|
+
* import { createSign } from "@std/internal";
|
54
|
+
* import { assertEquals } from "@std/assert";
|
55
|
+
*
|
56
|
+
* assertEquals(createSign("added"), "+ ");
|
57
|
+
* assertEquals(createSign("removed"), "- ");
|
58
|
+
* assertEquals(createSign("common"), " ");
|
59
|
+
* ```
|
60
|
+
*/
|
61
|
+
export function createSign(diffType: DiffType): string {
|
62
|
+
switch (diffType) {
|
63
|
+
case "added":
|
64
|
+
return "+ ";
|
65
|
+
case "removed":
|
66
|
+
return "- ";
|
67
|
+
default:
|
68
|
+
return " ";
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
/** Options for {@linkcode buildMessage}. */
|
73
|
+
export interface BuildMessageOptions {
|
74
|
+
/**
|
75
|
+
* Whether to output the diff as a single string.
|
76
|
+
*
|
77
|
+
* @default {false}
|
78
|
+
*/
|
79
|
+
stringDiff?: boolean;
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Builds a message based on the provided diff result.
|
84
|
+
*
|
85
|
+
* @param diffResult The diff result array.
|
86
|
+
* @param options Optional parameters for customizing the message.
|
87
|
+
*
|
88
|
+
* @returns An array of strings representing the built message.
|
89
|
+
*
|
90
|
+
* @example Usage
|
91
|
+
* ```ts no-assert
|
92
|
+
* import { diffStr, buildMessage } from "@std/internal";
|
93
|
+
*
|
94
|
+
* const diffResult = diffStr("Hello, world!", "Hello, world");
|
95
|
+
*
|
96
|
+
* console.log(buildMessage(diffResult));
|
97
|
+
* // [
|
98
|
+
* // "",
|
99
|
+
* // "",
|
100
|
+
* // " [Diff] Actual / Expected",
|
101
|
+
* // "",
|
102
|
+
* // "",
|
103
|
+
* // "- Hello, world!",
|
104
|
+
* // "+ Hello, world",
|
105
|
+
* // "",
|
106
|
+
* // ]
|
107
|
+
* ```
|
108
|
+
*/
|
109
|
+
export function buildMessage(
|
110
|
+
diffResult: ReadonlyArray<DiffResult<string>>,
|
111
|
+
options: BuildMessageOptions = {},
|
112
|
+
): string[] {
|
113
|
+
const { stringDiff = false } = options;
|
114
|
+
const messages = [
|
115
|
+
"",
|
116
|
+
"",
|
117
|
+
` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${
|
118
|
+
green(bold("Expected"))
|
119
|
+
}`,
|
120
|
+
"",
|
121
|
+
"",
|
122
|
+
];
|
123
|
+
const diffMessages = diffResult.map((result) => {
|
124
|
+
const color = createColor(result.type);
|
125
|
+
const line = result.details?.map((detail) =>
|
126
|
+
detail.type !== "common"
|
127
|
+
? createColor(detail.type, true)(detail.value)
|
128
|
+
: detail.value
|
129
|
+
).join("") ?? result.value;
|
130
|
+
return color(`${createSign(result.type)}${line}`);
|
131
|
+
});
|
132
|
+
messages.push(...(stringDiff ? [diffMessages.join("")] : diffMessages), "");
|
133
|
+
return messages;
|
134
|
+
}
|