@vbarbarosh/node-helpers 3.75.0 → 3.76.1
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/README.md +29 -3
- package/dist/browser.js +1 -2504
- package/dist/index.html +1 -1
- package/package.json +33 -12
- package/src/HeartbeatServer.js +24 -3
- package/src/HeartbeatServer.md +33 -0
- package/src/array_chunk.js +1 -1
- package/src/array_chunk.md +8 -0
- package/src/array_chunk_balanced.md +14 -0
- package/src/array_fps.md +12 -0
- package/src/array_gcd.js +4 -2
- package/src/array_gcd.md +2 -1
- package/src/array_group.js +3 -3
- package/src/array_group.md +14 -0
- package/src/array_group_map.js +3 -3
- package/src/array_group_map.md +13 -0
- package/src/array_index.js +2 -2
- package/src/array_index.md +9 -0
- package/src/array_lcm.js +4 -2
- package/src/array_lcm.md +2 -1
- package/src/array_max.js +11 -4
- package/src/array_max.md +1 -1
- package/src/array_min.js +11 -4
- package/src/array_min.md +1 -1
- package/src/array_permutations.js +4 -0
- package/src/array_permutations.md +13 -0
- package/src/array_sort.js +7 -2
- package/src/array_sort.md +13 -0
- package/src/array_sort_other.js +8 -5
- package/src/array_sort_other.md +11 -0
- package/src/array_sum.js +2 -2
- package/src/array_sum.md +8 -0
- package/src/array_unique.js +2 -2
- package/src/array_unique_last.js +2 -2
- package/src/assert_valid_expires_at.md +10 -0
- package/src/clamp.md +9 -0
- package/src/cli-apps/watchdog.js +5 -0
- package/src/cli.js +3 -1
- package/src/cli.md +15 -0
- package/src/const_stream.md +7 -0
- package/src/const_type.md +5 -0
- package/src/countdown.js +22 -5
- package/src/countdown.md +21 -0
- package/src/crypto_decrypt_aes256.md +13 -0
- package/src/crypto_encrypt_aes256.md +13 -0
- package/src/crypto_hash_md5.md +10 -0
- package/src/crypto_hash_sha256.md +10 -0
- package/src/crypto_hmac_sha256.md +11 -0
- package/src/date_add_hours.md +8 -0
- package/src/date_add_milliseconds.md +4 -0
- package/src/date_add_minutes.md +4 -0
- package/src/date_add_months.md +13 -0
- package/src/date_add_seconds.md +4 -0
- package/src/date_diff_seconds.md +4 -0
- package/src/date_is_leap_year.md +9 -0
- package/src/escape_content_disposition.js +6 -3
- package/src/escape_content_disposition.md +13 -0
- package/src/escape_regexp.md +7 -0
- package/src/eta.js +7 -1
- package/src/eta.md +18 -0
- package/src/factorize_ms.js +3 -0
- package/src/factorize_ms.md +10 -0
- package/src/fastdl.js +14 -3
- package/src/fcmp_dates.md +12 -0
- package/src/fcmp_default.js +7 -0
- package/src/fcmp_default.md +29 -0
- package/src/fcmp_default_desc.js +4 -7
- package/src/fcmp_default_desc.md +10 -0
- package/src/fcmp_from_spec.md +13 -0
- package/src/fcmp_numbers.md +11 -0
- package/src/fcmp_tuples.md +17 -0
- package/src/fcmp_utf8_bin.md +14 -0
- package/src/fcmp_utf8_ci.md +14 -0
- package/src/fcmp_utf8_cs.md +15 -0
- package/src/fcmp_utf8_natural_bin.js +38 -0
- package/src/fcmp_utf8_natural_bin.md +8 -0
- package/src/fcmp_utf8_natural_ci.md +13 -0
- package/src/fcmp_utf8_natural_cs.md +13 -0
- package/src/fcmpx.md +26 -9
- package/src/filter1_from_spec.js +3 -3
- package/src/format_bytes.md +15 -0
- package/src/format_date.md +7 -0
- package/src/format_date_fs.md +7 -0
- package/src/format_date_human.md +6 -0
- package/src/format_date_ymd.md +6 -0
- package/src/format_error_report.js +3 -3
- package/src/format_error_report.md +12 -0
- package/src/format_kilo.md +13 -0
- package/src/format_ms.js +3 -2
- package/src/format_ms.md +12 -0
- package/src/format_ms2.js +6 -3
- package/src/format_ms2.md +12 -0
- package/src/format_ms3.js +3 -2
- package/src/format_ms3.md +12 -0
- package/src/format_percents.md +10 -0
- package/src/format_progress_bytes.md +13 -0
- package/src/format_progress_kilo.md +10 -0
- package/src/format_seconds.md +11 -0
- package/src/format_thousands.md +9 -0
- package/src/fs_append.md +7 -0
- package/src/fs_append_json.md +8 -0
- package/src/fs_append_utf8.md +6 -0
- package/src/fs_assert_file_exists.md +3 -0
- package/src/fs_assert_file_readable.js +1 -1
- package/src/fs_assert_file_readable.md +3 -0
- package/src/fs_assert_file_socket.md +2 -0
- package/src/fs_copy.md +7 -0
- package/src/fs_copy_excl.md +2 -0
- package/src/fs_exists.md +6 -0
- package/src/fs_fclose.md +5 -0
- package/src/fs_fi.js +13 -1
- package/src/fs_fi.md +11 -0
- package/src/fs_file_md5.md +8 -0
- package/src/fs_find.md +7 -0
- package/src/fs_fopen.md +6 -0
- package/src/fs_fread.js +2 -2
- package/src/fs_fread.md +11 -0
- package/src/fs_fsize.md +2 -0
- package/src/fs_fstat.md +2 -0
- package/src/fs_fwrite.js +2 -2
- package/src/fs_fwrite.md +9 -0
- package/src/fs_list.md +5 -0
- package/src/fs_list_deep.md +5 -0
- package/src/fs_ls.md +2 -0
- package/src/fs_lsr.md +4 -0
- package/src/fs_lstat.md +3 -0
- package/src/fs_mkdir.md +3 -0
- package/src/fs_mkdirp.js +3 -30
- package/src/fs_mkdirp.md +7 -0
- package/src/fs_path_basename.md +2 -0
- package/src/fs_path_dirname.md +2 -0
- package/src/fs_path_extname.md +9 -0
- package/src/fs_path_join.md +2 -0
- package/src/fs_path_relative.md +2 -0
- package/src/fs_path_resolve.md +2 -0
- package/src/fs_path_tempdir.md +2 -0
- package/src/fs_path_untildify.md +8 -0
- package/src/fs_read.md +3 -0
- package/src/fs_read_buffer.md +5 -0
- package/src/fs_read_json.md +6 -0
- package/src/fs_read_lines.md +7 -0
- package/src/fs_read_stream.md +2 -0
- package/src/fs_read_utf8.md +5 -0
- package/src/fs_readdir.md +3 -0
- package/src/fs_readlink.md +6 -0
- package/src/fs_rename.md +6 -0
- package/src/fs_rm.md +4 -0
- package/src/fs_rmdir.md +3 -0
- package/src/fs_rmf.md +2 -0
- package/src/fs_rmrf.md +8 -0
- package/src/fs_sha256.js +16 -0
- package/src/fs_sha256.md +9 -0
- package/src/fs_size.js +2 -2
- package/src/fs_size.md +6 -0
- package/src/fs_stat.md +2 -0
- package/src/fs_tempdir.js +20 -5
- package/src/fs_touch.md +6 -0
- package/src/fs_walk.js +2 -2
- package/src/fs_walk.md +14 -0
- package/src/fs_write.md +3 -0
- package/src/fs_write_json.md +7 -0
- package/src/fs_write_stream.md +2 -0
- package/src/gettype.md +13 -0
- package/src/http_delete.md +11 -0
- package/src/http_get_blob.md +8 -0
- package/src/http_get_buffer.md +10 -0
- package/src/http_get_file.js +8 -8
- package/src/http_get_file.md +14 -0
- package/src/http_get_json.md +10 -0
- package/src/http_get_stream.md +14 -0
- package/src/http_get_stream_range.js +27 -9
- package/src/http_get_stream_range.md +22 -0
- package/src/http_get_utf8.md +9 -0
- package/src/http_head.md +9 -0
- package/src/http_patch_json.md +10 -0
- package/src/http_post_json.md +11 -0
- package/src/http_post_multipart.md +15 -0
- package/src/http_post_urlencoded.md +11 -0
- package/src/http_put_buffer.md +9 -0
- package/src/http_put_file.js +9 -6
- package/src/http_put_file.md +16 -0
- package/src/http_put_json.md +11 -0
- package/src/http_put_utf8.md +9 -0
- package/src/http_range_parse.js +6 -3
- package/src/http_range_parse.md +18 -0
- package/src/http_stream_range.js +35 -22
- package/src/http_stream_range.md +29 -0
- package/src/identity.md +2 -0
- package/src/ignore.md +2 -0
- package/src/json_stringify_safe.md +10 -0
- package/src/json_stringify_stable.md +9 -0
- package/src/logger.js +2 -3
- package/src/logger.md +15 -0
- package/src/make_progress.js +8 -5
- package/src/make_progress.md +20 -0
- package/src/math_gcd.js +2 -1
- package/src/mongo_stream_upsert.js +10 -3
- package/src/mongo_stream_upsert.md +17 -0
- package/src/mongo_stream_write.js +10 -3
- package/src/mongo_stream_write.md +16 -0
- package/src/msval.md +10 -0
- package/src/now_fs.md +7 -0
- package/src/now_human.md +6 -0
- package/src/object_defaults.md +11 -0
- package/src/object_schema.js +2 -1
- package/src/object_schema.md +12 -0
- package/src/object_walk_preorder.md +16 -0
- package/src/parallel.js +23 -10
- package/src/parse_bytes.js +4 -2
- package/src/parse_bytes.md +15 -0
- package/src/parse_hms.js +1 -1
- package/src/parse_http_content_range.js +9 -5
- package/src/parse_http_content_range.md +16 -0
- package/src/perf_end_human.md +10 -0
- package/src/perf_end_ms.md +8 -0
- package/src/perf_measure.md +10 -0
- package/src/perf_measure_human.md +8 -0
- package/src/perf_start.md +9 -0
- package/src/pgid_exists.md +6 -0
- package/src/pgid_kill_grace.js +1 -1
- package/src/pgid_kill_grace.md +15 -0
- package/src/pid_exists.md +5 -0
- package/src/pid_kill_grace.js +1 -1
- package/src/pid_kill_grace.md +14 -0
- package/src/plural.md +13 -0
- package/src/random_hex.md +9 -0
- package/src/random_int.md +8 -0
- package/src/range.js +4 -2
- package/src/range.md +2 -0
- package/src/redis_connect.js +1 -1
- package/src/redis_connect.md +10 -0
- package/src/redis_lshift.md +14 -0
- package/src/redis_poll.js +1 -0
- package/src/redis_poll.md +17 -0
- package/src/redis_poll_zshift_callback_rpush.js +1 -2
- package/src/redis_poll_zshift_callback_rpush.md +17 -0
- package/src/redis_poll_zshift_spawn_rpush.js +2 -1
- package/src/redis_poll_zshift_spawn_rpush.md +20 -0
- package/src/redis_zshift.md +14 -0
- package/src/round.js +7 -8
- package/src/round.md +15 -0
- package/src/sanitize_dash_name.md +13 -0
- package/src/sanitize_filename.md +9 -0
- package/src/sanitize_var_name.md +14 -0
- package/src/sftp_get_file_info.js +2 -2
- package/src/sftp_get_file_info.md +14 -0
- package/src/sftp_get_stream_range.js +32 -22
- package/src/sftp_get_stream_range.md +20 -0
- package/src/shell_curl_progress.js +2 -1
- package/src/shell_curl_progress.md +17 -0
- package/src/shell_lines.js +2 -2
- package/src/shell_lines.md +1 -1
- package/src/shell_spawn.js +7 -0
- package/src/shell_ytdlp_progress.js +2 -1
- package/src/shell_ytdlp_progress.md +17 -0
- package/src/str_camel_to_snake.md +11 -0
- package/src/str_parse_kv.md +11 -0
- package/src/stream_curl_progress.md +14 -0
- package/src/stream_data_ln.js +7 -1
- package/src/stream_discard.md +8 -0
- package/src/stream_group.md +3 -0
- package/src/stream_gunzip.md +7 -0
- package/src/stream_hash.md +10 -0
- package/src/stream_map.js +8 -1
- package/src/stream_map_parallel.js +9 -1
- package/src/stream_md5.md +9 -0
- package/src/stream_multiplex.js +11 -0
- package/src/stream_multiplex.md +16 -0
- package/src/stream_through.md +3 -0
- package/src/stream_transform.md +2 -0
- package/src/stream_xml_analyze.js +9 -1
- package/src/stream_xml_parse.js +9 -1
- package/src/stream_ytdlp_progress.js +1 -1
- package/src/stream_ytdlp_progress.md +18 -0
- package/src/strtr.js +15 -5
- package/src/strtr.md +11 -0
- package/src/urlclean.js +9 -2
- package/src/urlmod.js +22 -11
- package/src/urlmod.md +15 -3
- package/src/urlparts.md +17 -0
- package/src/wait_while.js +1 -1
- package/src/wait_while.md +1 -1
- package/src/HeartbeatServer.test.js +0 -31
- package/src/array_chunk.test.js +0 -24
- package/src/array_chunk_balanced.test.js +0 -37
- package/src/array_fps.test.js +0 -72
- package/src/array_gcd.test.js +0 -10
- package/src/array_index.test.js +0 -14
- package/src/array_lcm.test.js +0 -12
- package/src/array_max.test.js +0 -20
- package/src/array_min.test.js +0 -20
- package/src/array_permutations.test.js +0 -20
- package/src/array_sort.test.js +0 -85
- package/src/array_sort_other.test.js +0 -9
- package/src/array_sum.test.js +0 -11
- package/src/cli-apps/watchdog.d/connect_close.js +0 -17
- package/src/cli-apps/watchdog.d/connect_close2.js +0 -20
- package/src/cli-apps/watchdog.d/connect_close3.js +0 -25
- package/src/cli-apps/watchdog.d/connect_no_ping.js +0 -13
- package/src/cli-apps/watchdog.d/early_exit.js +0 -7
- package/src/cli-apps/watchdog.d/flood.js +0 -13
- package/src/cli-apps/watchdog.d/flood2.js +0 -15
- package/src/cli-apps/watchdog.d/hang.js +0 -8
- package/src/cli-apps/watchdog.d/huge_delay.js +0 -18
- package/src/cli-apps/watchdog.d/ignore_sigterm.js +0 -29
- package/src/cli-apps/watchdog.d/late_heartbeat.js +0 -21
- package/src/cli-apps/watchdog.d/my-exit-after-2-pings.js +0 -16
- package/src/cli-apps/watchdog.d/my-happy-path.js +0 -16
- package/src/cli-apps/watchdog.d/my-ignore-sigterm.js +0 -22
- package/src/cli-apps/watchdog.d/my-never-ping.js +0 -15
- package/src/cli-apps/watchdog.d/no_heartbeat.js +0 -5
- package/src/cli-apps/watchdog.d/ok.js +0 -17
- package/src/cli-apps/watchdog.d/quick-exit-after-2-pings.js +0 -15
- package/src/cli-apps/watchdog.d/quick-hang-after-1-ping.js +0 -15
- package/src/cli-apps/watchdog.d/spawn_children.js +0 -14
- package/src/cli-apps/watchdog.test.js +0 -48
- package/src/crypto_encrypt_aes256.test.js +0 -10
- package/src/crypto_hash_sha256.test.js +0 -10
- package/src/date_add_months.test.js +0 -40
- package/src/date_is_leap_year.test.js +0 -14
- package/src/escape_content_disposition.test.js +0 -22
- package/src/fcmp_from_spec.test.js +0 -91
- package/src/fcmpx.test.js +0 -173
- package/src/filter1_from_spec.test.js +0 -31
- package/src/format_bytes.test.js +0 -22
- package/src/format_error_report.d/src/1.js +0 -26
- package/src/format_error_report.d/src/2.js +0 -29
- package/src/format_kilo.test.js +0 -25
- package/src/format_ms.test.js +0 -33
- package/src/format_ms2.test.js +0 -33
- package/src/format_ms3.test.js +0 -33
- package/src/format_percents.test.js +0 -22
- package/src/format_progress_bytes.test.js +0 -19
- package/src/format_progress_kilo.test.js +0 -19
- package/src/format_seconds.test.js +0 -42
- package/src/format_thousands.test.js +0 -28
- package/src/fs_file_md5.test.js +0 -11
- package/src/fs_mkdirp.test.js +0 -24
- package/src/fs_path_extname.test.js +0 -22
- package/src/gettype.test.js +0 -27
- package/src/object_schema.test.js +0 -15
- package/src/object_walk_preorder.test.js +0 -17
- package/src/parallel.test.js +0 -11
- package/src/parse_bytes.test.js +0 -21
- package/src/parse_hms.test.js +0 -32
- package/src/parse_http_content_range.test.js +0 -14
- package/src/pid_kill_grace.d/ignore-sigterm-for-10ms.js +0 -33
- package/src/pid_kill_grace.d/ignore-sigterm.js +0 -22
- package/src/pid_kill_grace.test.js +0 -63
- package/src/ping_socket.test.js +0 -58
- package/src/plural.test.js +0 -20
- package/src/range.test.js +0 -41
- package/src/redis_lshift.test.js +0 -57
- package/src/redis_zshift.test.js +0 -58
- package/src/round.test.js +0 -56
- package/src/sanitize_dash_name.test.js +0 -59
- package/src/sanitize_var_name.test.js +0 -39
- package/src/shell_spawn.test.js +0 -30
- package/src/str_camel_to_snake.test.js +0 -17
- package/src/stream_curl_progress.d/basic +0 -3
- package/src/stream_curl_progress.d/basic.json +0 -42
- package/src/stream_curl_progress.test.js +0 -17
- package/src/stream_data_ln.test.js +0 -24
- package/src/stream_map_parallel.test.js +0 -26
- package/src/stream_multiplex.test.js +0 -67
- package/src/stream_strpbrk.test.js +0 -29
- package/src/urlclean.test.js +0 -18
- package/src/urlmod.test.js +0 -40
- package/src/urlparts.test.js +0 -294
package/src/urlmod.test.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const urlmod = require('./urlmod');
|
|
3
|
-
|
|
4
|
-
describe('urlmod', function () {
|
|
5
|
-
it('should take no args', function () {
|
|
6
|
-
assert.deepEqual(urlmod(), '');
|
|
7
|
-
});
|
|
8
|
-
it('should take basic args', function () {
|
|
9
|
-
assert.deepEqual(urlmod('?a=1'), '?a=1');
|
|
10
|
-
assert.deepEqual(urlmod('?a=1', {a: 2}), '?a=2');
|
|
11
|
-
assert.deepEqual(urlmod('?a=1', {a: null}), '');
|
|
12
|
-
assert.deepEqual(urlmod('?a=1', {b: 1}), '?a=1&b=1');
|
|
13
|
-
assert.deepEqual(urlmod('?a=1', {b: 1, a: 2}), '?a=2&b=1');
|
|
14
|
-
assert.deepEqual(urlmod('?a=1', {a: true}), '?a=1');
|
|
15
|
-
assert.deepEqual(urlmod('?a=1', {a: false, b: true}), '?a=0&b=1');
|
|
16
|
-
});
|
|
17
|
-
it('should take `location`', function () {
|
|
18
|
-
// const elem = document.createElement('A');
|
|
19
|
-
// elem.href = 'http://www.example.com/some/path?a=1';
|
|
20
|
-
// const location = elem.href;
|
|
21
|
-
const location = {
|
|
22
|
-
toString: function () {
|
|
23
|
-
return 'http://www.example.com/some/path?a=1';
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
assert.deepEqual(urlmod(location, {b: 2}), 'http://www.example.com/some/path?a=1&b=2');
|
|
27
|
-
});
|
|
28
|
-
it('should keep hash part', function () {
|
|
29
|
-
assert.deepEqual(urlmod('#ex', {b: 2}), '?b=2#ex');
|
|
30
|
-
assert.deepEqual(urlmod('#ex?a=1#ex', {b: 2}), '?b=2#ex?a=1#ex');
|
|
31
|
-
assert.deepEqual(urlmod('?a=1#ex', {b: 2}), '?a=1&b=2#ex');
|
|
32
|
-
assert.deepEqual(urlmod('/#ex', {b: 2}), '/?b=2#ex');
|
|
33
|
-
assert.deepEqual(urlmod('http://www.example.com/some/path?a=1#ex', {b: 2}), 'http://www.example.com/some/path?a=1&b=2#ex');
|
|
34
|
-
});
|
|
35
|
-
it('should keep port', function () {
|
|
36
|
-
const actual = urlmod('http://localhost:3000/auth/sign-in', {return: '/auth/profile'});
|
|
37
|
-
const expected = 'http://localhost:3000/auth/sign-in?return=%2Fauth%2Fprofile';
|
|
38
|
-
assert.strictEqual(actual, expected);
|
|
39
|
-
})
|
|
40
|
-
});
|
package/src/urlparts.test.js
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const edge_values = require('@vbarbarosh/type-helpers/src/edge_values');
|
|
3
|
-
const urlparts = require('./urlparts');
|
|
4
|
-
|
|
5
|
-
const extra_edge_values = [
|
|
6
|
-
// whitespace strings
|
|
7
|
-
{label: '" "', value: ' '},
|
|
8
|
-
{label: '"\\t"', value: '\t'},
|
|
9
|
-
{label: '"\\n"', value: '\n'},
|
|
10
|
-
{label: '"\\r\\n"', value: '\r\n'},
|
|
11
|
-
|
|
12
|
-
// numeric strings
|
|
13
|
-
{label: '"0"', value: '0'},
|
|
14
|
-
{label: '"1"', value: '1'},
|
|
15
|
-
{label: '"NaN"', value: 'NaN'},
|
|
16
|
-
{label: '"Infinity"', value: 'Infinity'},
|
|
17
|
-
|
|
18
|
-
// weird unicode
|
|
19
|
-
{label: '"💩"', value: '💩'},
|
|
20
|
-
{label: '"😀"', value: '😀'},
|
|
21
|
-
{label: '"привет"', value: 'привет'},
|
|
22
|
-
{label: '"こんにちは"', value: 'こんにちは'},
|
|
23
|
-
|
|
24
|
-
// dangerous chars
|
|
25
|
-
{label: '"<script>"', value: '<script>'},
|
|
26
|
-
{label: '"../"', value: '../'},
|
|
27
|
-
{label: '"%20"', value: '%20'},
|
|
28
|
-
{label: '"a?b=c"', value: 'a?b=c'},
|
|
29
|
-
{label: '"a#b"', value: 'a#b'},
|
|
30
|
-
|
|
31
|
-
// arrays
|
|
32
|
-
{label: '[1,2,3]', value: [1, 2, 3]},
|
|
33
|
-
{label: '[null]', value: [null]},
|
|
34
|
-
{label: '[undefined]', value: [undefined]},
|
|
35
|
-
{label: 'new Array(5)', value: new Array(5)},
|
|
36
|
-
|
|
37
|
-
// typed arrays
|
|
38
|
-
{label: 'Uint8Array', value: new Uint8Array([1, 2, 3])},
|
|
39
|
-
{label: 'Buffer', value: Buffer.from('abc')},
|
|
40
|
-
|
|
41
|
-
// objects
|
|
42
|
-
{label: '{a:1}', value: {a: 1}},
|
|
43
|
-
{label: 'Object.create(null)', value: Object.create(null)},
|
|
44
|
-
|
|
45
|
-
// custom coercion
|
|
46
|
-
{label: 'toString() => x', value: {toString() {return 'x';}}},
|
|
47
|
-
{label: 'valueOf() => 123', value: {valueOf() {return 123;}}},
|
|
48
|
-
|
|
49
|
-
// dates
|
|
50
|
-
{label: 'new Date()', value: new Date()},
|
|
51
|
-
{label: 'Invalid Date', value: new Date('invalid')},
|
|
52
|
-
|
|
53
|
-
// regexp
|
|
54
|
-
{label: '/foo/g', value: /foo/g},
|
|
55
|
-
|
|
56
|
-
// maps/sets
|
|
57
|
-
{label: 'Map', value: new Map()},
|
|
58
|
-
{label: 'Set', value: new Set()},
|
|
59
|
-
{label: 'WeakMap', value: new WeakMap()},
|
|
60
|
-
{label: 'WeakSet', value: new WeakSet()},
|
|
61
|
-
|
|
62
|
-
// promises
|
|
63
|
-
{label: 'Promise.resolve(1)', value: Promise.resolve(1)},
|
|
64
|
-
|
|
65
|
-
// errors
|
|
66
|
-
{label: 'Error', value: new Error('boom')},
|
|
67
|
-
{label: 'TypeError', value: new TypeError('boom')},
|
|
68
|
-
|
|
69
|
-
// wrappers
|
|
70
|
-
{label: 'new String()', value: new String('abc')},
|
|
71
|
-
{label: 'new Number()', value: new Number(123)},
|
|
72
|
-
{label: 'new Boolean()', value: new Boolean(false)},
|
|
73
|
-
|
|
74
|
-
// url-like
|
|
75
|
-
{label: 'new URL("https://example.com")', value: new URL('https://example.com')},
|
|
76
|
-
|
|
77
|
-
// bigint
|
|
78
|
-
{label: '1n', value: 1n},
|
|
79
|
-
{label: '-1n', value: -1n},
|
|
80
|
-
|
|
81
|
-
// special numbers
|
|
82
|
-
{label: 'Number.EPSILON', value: Number.EPSILON},
|
|
83
|
-
|
|
84
|
-
// proxy
|
|
85
|
-
{label: 'Proxy', value: new Proxy({}, {})},
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
const happy_paths = [
|
|
89
|
-
{
|
|
90
|
-
label: 'parses full https url',
|
|
91
|
-
input: 'https://john:secret@example.com:8080/users/15?page=2#top',
|
|
92
|
-
expected: {
|
|
93
|
-
href: 'https://john:secret@example.com:8080/users/15?page=2#top',
|
|
94
|
-
protocol: 'https:',
|
|
95
|
-
hostname: 'example.com',
|
|
96
|
-
username: 'john',
|
|
97
|
-
password: 'secret',
|
|
98
|
-
host: 'example.com:8080',
|
|
99
|
-
port: '8080',
|
|
100
|
-
path: '/users/15',
|
|
101
|
-
search: '?page=2',
|
|
102
|
-
hash: '#top',
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
label: 'parses https url without auth',
|
|
107
|
-
input: 'https://example.com/users',
|
|
108
|
-
expected: {
|
|
109
|
-
href: 'https://example.com/users',
|
|
110
|
-
protocol: 'https:',
|
|
111
|
-
hostname: 'example.com',
|
|
112
|
-
username: '',
|
|
113
|
-
password: '',
|
|
114
|
-
host: 'example.com',
|
|
115
|
-
port: '',
|
|
116
|
-
path: '/users',
|
|
117
|
-
search: '',
|
|
118
|
-
hash: '',
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
label: 'parses root url',
|
|
123
|
-
input: 'https://example.com',
|
|
124
|
-
expected: {
|
|
125
|
-
href: 'https://example.com/',
|
|
126
|
-
protocol: 'https:',
|
|
127
|
-
hostname: 'example.com',
|
|
128
|
-
username: '',
|
|
129
|
-
password: '',
|
|
130
|
-
host: 'example.com',
|
|
131
|
-
port: '',
|
|
132
|
-
path: '/',
|
|
133
|
-
search: '',
|
|
134
|
-
hash: '',
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
label: 'parses relative path',
|
|
139
|
-
input: '/users?page=5',
|
|
140
|
-
expected: {
|
|
141
|
-
href: 'fake://fake/users?page=5',
|
|
142
|
-
protocol: 'fake:',
|
|
143
|
-
hostname: 'fake',
|
|
144
|
-
username: '',
|
|
145
|
-
password: '',
|
|
146
|
-
host: 'fake',
|
|
147
|
-
port: '',
|
|
148
|
-
path: '/users',
|
|
149
|
-
search: '?page=5',
|
|
150
|
-
hash: '',
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
label: 'parses hash',
|
|
155
|
-
input: 'https://example.com/docs#intro',
|
|
156
|
-
expected: {
|
|
157
|
-
href: 'https://example.com/docs#intro',
|
|
158
|
-
protocol: 'https:',
|
|
159
|
-
hostname: 'example.com',
|
|
160
|
-
username: '',
|
|
161
|
-
password: '',
|
|
162
|
-
host: 'example.com',
|
|
163
|
-
port: '',
|
|
164
|
-
path: '/docs',
|
|
165
|
-
search: '',
|
|
166
|
-
hash: '#intro',
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
label: 'parses query string',
|
|
171
|
-
input: 'https://example.com?a=1&b=2',
|
|
172
|
-
expected: {
|
|
173
|
-
href: 'https://example.com/?a=1&b=2',
|
|
174
|
-
protocol: 'https:',
|
|
175
|
-
hostname: 'example.com',
|
|
176
|
-
username: '',
|
|
177
|
-
password: '',
|
|
178
|
-
host: 'example.com',
|
|
179
|
-
port: '',
|
|
180
|
-
path: '/',
|
|
181
|
-
search: '?a=1&b=2',
|
|
182
|
-
hash: '',
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
label: 'parses localhost with port',
|
|
187
|
-
input: 'http://localhost:3000/foo',
|
|
188
|
-
expected: {
|
|
189
|
-
href: 'http://localhost:3000/foo',
|
|
190
|
-
protocol: 'http:',
|
|
191
|
-
hostname: 'localhost',
|
|
192
|
-
username: '',
|
|
193
|
-
password: '',
|
|
194
|
-
host: 'localhost:3000',
|
|
195
|
-
port: '3000',
|
|
196
|
-
path: '/foo',
|
|
197
|
-
search: '',
|
|
198
|
-
hash: '',
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
label: 'parses ftp url',
|
|
203
|
-
input: 'ftp://example.com/file.txt',
|
|
204
|
-
expected: {
|
|
205
|
-
href: 'ftp://example.com/file.txt',
|
|
206
|
-
protocol: 'ftp:',
|
|
207
|
-
hostname: 'example.com',
|
|
208
|
-
username: '',
|
|
209
|
-
password: '',
|
|
210
|
-
host: 'example.com',
|
|
211
|
-
port: '',
|
|
212
|
-
path: '/file.txt',
|
|
213
|
-
search: '',
|
|
214
|
-
hash: '',
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
];
|
|
218
|
-
|
|
219
|
-
describe('urlparts', function () {
|
|
220
|
-
it('no args', function () {
|
|
221
|
-
assert.deepStrictEqual(urlparts(), {
|
|
222
|
-
href: 'fake://fake/',
|
|
223
|
-
protocol: 'fake:',
|
|
224
|
-
hostname: 'fake',
|
|
225
|
-
username: '',
|
|
226
|
-
password: '',
|
|
227
|
-
host: 'fake',
|
|
228
|
-
port: '',
|
|
229
|
-
path: '/',
|
|
230
|
-
search: '',
|
|
231
|
-
hash: '',
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
describe('happy paths', function () {
|
|
236
|
-
for (const item of happy_paths) {
|
|
237
|
-
it(item.label, function () {
|
|
238
|
-
const actual = urlparts(item.input);
|
|
239
|
-
assert.deepStrictEqual(actual, item.expected);
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
describe('edge values', function () {
|
|
245
|
-
for (const item of [...edge_values, ...extra_edge_values]) {
|
|
246
|
-
it(item.label, function () {
|
|
247
|
-
if (typeof item.value === 'string') {
|
|
248
|
-
const tmp = new URL(item.value, 'fake://fake/');
|
|
249
|
-
assert.deepStrictEqual(urlparts(item.value), {
|
|
250
|
-
href: tmp.href,
|
|
251
|
-
protocol: tmp.protocol,
|
|
252
|
-
hostname: tmp.hostname,
|
|
253
|
-
username: tmp.username,
|
|
254
|
-
password: tmp.password,
|
|
255
|
-
host: tmp.host,
|
|
256
|
-
port: tmp.port,
|
|
257
|
-
path: tmp.pathname,
|
|
258
|
-
search: tmp.search,
|
|
259
|
-
hash: tmp.hash,
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
else if (item.value instanceof URL) {
|
|
263
|
-
const tmp = item.value;
|
|
264
|
-
assert.deepStrictEqual(urlparts(item.value), {
|
|
265
|
-
href: tmp.href,
|
|
266
|
-
protocol: tmp.protocol,
|
|
267
|
-
hostname: tmp.hostname,
|
|
268
|
-
username: tmp.username,
|
|
269
|
-
password: tmp.password,
|
|
270
|
-
host: tmp.host,
|
|
271
|
-
port: tmp.port,
|
|
272
|
-
path: tmp.pathname,
|
|
273
|
-
search: tmp.search,
|
|
274
|
-
hash: tmp.hash,
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
assert.deepStrictEqual(urlparts(item.value), {
|
|
279
|
-
href: 'fake://fake/',
|
|
280
|
-
protocol: 'fake:',
|
|
281
|
-
hostname: 'fake',
|
|
282
|
-
username: '',
|
|
283
|
-
password: '',
|
|
284
|
-
host: 'fake',
|
|
285
|
-
port: '',
|
|
286
|
-
path: '/',
|
|
287
|
-
search: '',
|
|
288
|
-
hash: '',
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
});
|