locutus 2.0.32 → 2.0.34
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 +18 -0
- package/_data/rosetta.yml +325 -0
- package/awk/builtin/index.js +3 -0
- package/awk/builtin/int.js +13 -0
- package/awk/builtin/length.js +16 -0
- package/awk/builtin/substr.js +23 -0
- package/c/ctype/index.js +8 -0
- package/c/ctype/isalnum.js +15 -0
- package/c/ctype/isalpha.js +17 -0
- package/c/ctype/isdigit.js +15 -0
- package/c/ctype/islower.js +15 -0
- package/c/ctype/isspace.js +15 -0
- package/c/ctype/isupper.js +15 -0
- package/c/ctype/tolower.js +15 -0
- package/c/ctype/toupper.js +15 -0
- package/c/index.js +2 -5
- package/c/math/abs.js +14 -18
- package/c/math/frexp.js +19 -20
- package/c/math/index.js +2 -5
- package/c/stdio/index.js +1 -4
- package/c/stdio/sprintf.js +71 -81
- package/c/stdlib/atof.js +15 -0
- package/c/stdlib/atoi.js +17 -0
- package/c/stdlib/index.js +2 -0
- package/c/string/index.js +5 -0
- package/c/string/strcat.js +12 -0
- package/c/string/strchr.js +15 -0
- package/c/string/strcmp.js +21 -0
- package/c/string/strlen.js +12 -0
- package/c/string/strstr.js +15 -0
- package/clojure/Math/abs.js +13 -0
- package/clojure/Math/ceil.js +15 -0
- package/clojure/Math/floor.js +14 -0
- package/clojure/Math/index.js +3 -0
- package/elixir/Float/ceil.js +16 -0
- package/elixir/Float/floor.js +14 -0
- package/elixir/Float/index.js +2 -0
- package/elixir/Kernel/abs.js +13 -0
- package/elixir/Kernel/index.js +1 -0
- package/golang/index.js +1 -4
- package/golang/strconv/Atoi.js +26 -0
- package/golang/strconv/FormatBool.js +12 -0
- package/golang/strconv/FormatInt.js +21 -0
- package/golang/strconv/Itoa.js +14 -0
- package/golang/strconv/ParseBool.js +35 -0
- package/golang/strconv/ParseInt.js +27 -0
- package/golang/strconv/index.js +6 -0
- package/golang/strings/Compare.js +19 -0
- package/golang/strings/Contains.js +7 -9
- package/golang/strings/ContainsAny.js +18 -0
- package/golang/strings/Count.js +20 -22
- package/golang/strings/EqualFold.js +13 -0
- package/golang/strings/Fields.js +12 -0
- package/golang/strings/HasPrefix.js +15 -0
- package/golang/strings/HasSuffix.js +20 -0
- package/golang/strings/Index.js +11 -0
- package/golang/strings/Index2.js +9 -11
- package/golang/strings/IndexAny.js +18 -0
- package/golang/strings/Join.js +16 -0
- package/golang/strings/LastIndex.js +10 -12
- package/golang/strings/LastIndexAny.js +18 -0
- package/golang/strings/Repeat.js +19 -0
- package/golang/strings/Replace.js +44 -0
- package/golang/strings/Split.js +24 -0
- package/golang/strings/ToLower.js +9 -0
- package/golang/strings/ToUpper.js +9 -0
- package/golang/strings/Trim.js +19 -0
- package/golang/strings/TrimLeft.js +15 -0
- package/golang/strings/TrimPrefix.js +14 -0
- package/golang/strings/TrimRight.js +15 -0
- package/golang/strings/TrimSpace.js +10 -0
- package/golang/strings/TrimSuffix.js +14 -0
- package/golang/strings/index.js +25 -7
- package/index.js +5 -8
- package/julia/Base/abs.js +13 -0
- package/julia/Base/ceil.js +16 -0
- package/julia/Base/floor.js +14 -0
- package/julia/Base/index.js +3 -0
- package/lua/math/abs.js +13 -0
- package/lua/math/ceil.js +16 -0
- package/lua/math/floor.js +14 -0
- package/lua/math/index.js +3 -0
- package/package.json +37 -51
- package/perl/POSIX/ceil.js +16 -0
- package/perl/POSIX/floor.js +14 -0
- package/perl/POSIX/index.js +2 -0
- package/perl/core/index.js +1 -0
- package/perl/core/length.js +16 -0
- package/php/_helpers/_bc.js +524 -515
- package/php/_helpers/_phpCastString.js +20 -25
- package/php/_helpers/_php_cast_float.js +5 -10
- package/php/_helpers/_php_cast_int.js +6 -11
- package/php/_helpers/index.js +4 -7
- package/php/array/array_change_key_case.js +11 -16
- package/php/array/array_chunk.js +20 -23
- package/php/array/array_column.js +22 -72
- package/php/array/array_combine.js +13 -18
- package/php/array/array_count_values.js +35 -39
- package/php/array/array_diff.js +11 -14
- package/php/array/array_diff_assoc.js +11 -14
- package/php/array/array_diff_key.js +11 -14
- package/php/array/array_diff_uassoc.js +15 -19
- package/php/array/array_diff_ukey.js +14 -17
- package/php/array/array_fill.js +11 -13
- package/php/array/array_fill_keys.js +5 -8
- package/php/array/array_filter.js +12 -13
- package/php/array/array_flip.js +13 -15
- package/php/array/array_intersect.js +13 -16
- package/php/array/array_intersect_assoc.js +13 -16
- package/php/array/array_intersect_key.js +15 -18
- package/php/array/array_intersect_uassoc.js +17 -20
- package/php/array/array_intersect_ukey.js +17 -20
- package/php/array/array_key_exists.js +4 -7
- package/php/array/array_keys.js +22 -24
- package/php/array/array_map.js +24 -29
- package/php/array/array_merge.js +22 -25
- package/php/array/array_merge_recursive.js +51 -27
- package/php/array/array_multisort.js +138 -130
- package/php/array/array_pad.js +24 -26
- package/php/array/array_pop.js +10 -13
- package/php/array/array_product.js +15 -17
- package/php/array/array_push.js +16 -19
- package/php/array/array_rand.js +11 -14
- package/php/array/array_reduce.js +11 -14
- package/php/array/array_replace.js +9 -12
- package/php/array/array_replace_recursive.js +20 -24
- package/php/array/array_reverse.js +12 -15
- package/php/array/array_search.js +27 -29
- package/php/array/array_shift.js +3 -6
- package/php/array/array_slice.js +37 -39
- package/php/array/array_splice.js +64 -69
- package/php/array/array_sum.js +7 -12
- package/php/array/array_udiff.js +14 -17
- package/php/array/array_udiff_assoc.js +14 -17
- package/php/array/array_udiff_uassoc.js +17 -20
- package/php/array/array_uintersect.js +16 -19
- package/php/array/array_uintersect_uassoc.js +18 -21
- package/php/array/array_unique.js +12 -15
- package/php/array/array_unshift.js +4 -7
- package/php/array/array_values.js +11 -13
- package/php/array/array_walk.js +10 -15
- package/php/array/array_walk_recursive.js +15 -20
- package/php/array/arsort.js +50 -52
- package/php/array/asort.js +50 -51
- package/php/array/count.js +15 -14
- package/php/array/current.js +30 -32
- package/php/array/each.js +32 -35
- package/php/array/end.js +27 -30
- package/php/array/in_array.js +7 -10
- package/php/array/index.js +73 -76
- package/php/array/key.js +32 -34
- package/php/array/krsort.js +50 -51
- package/php/array/ksort.js +50 -51
- package/php/array/natcasesort.js +37 -38
- package/php/array/natsort.js +35 -36
- package/php/array/next.js +34 -36
- package/php/array/pos.js +10 -12
- package/php/array/prev.js +32 -34
- package/php/array/range.js +30 -33
- package/php/array/reset.js +24 -27
- package/php/array/rsort.js +47 -49
- package/php/array/shuffle.js +16 -18
- package/php/array/sizeof.js +3 -6
- package/php/array/sort.js +43 -45
- package/php/array/uasort.js +19 -21
- package/php/array/uksort.js +22 -24
- package/php/array/usort.js +20 -22
- package/php/bc/bcadd.js +16 -19
- package/php/bc/bccomp.js +12 -15
- package/php/bc/bcdiv.js +17 -20
- package/php/bc/bcmul.js +16 -19
- package/php/bc/bcround.js +21 -24
- package/php/bc/bcscale.js +8 -11
- package/php/bc/bcsub.js +16 -19
- package/php/bc/index.js +7 -10
- package/php/ctype/ctype_alnum.js +14 -16
- package/php/ctype/ctype_alpha.js +14 -16
- package/php/ctype/ctype_cntrl.js +9 -12
- package/php/ctype/ctype_digit.js +14 -16
- package/php/ctype/ctype_graph.js +14 -16
- package/php/ctype/ctype_lower.js +14 -16
- package/php/ctype/ctype_print.js +14 -16
- package/php/ctype/ctype_punct.js +14 -16
- package/php/ctype/ctype_space.js +9 -12
- package/php/ctype/ctype_upper.js +14 -16
- package/php/ctype/ctype_xdigit.js +14 -16
- package/php/ctype/index.js +11 -14
- package/php/datetime/checkdate.js +15 -17
- package/php/datetime/date.js +142 -123
- package/php/datetime/date_parse.js +18 -21
- package/php/datetime/getdate.js +38 -24
- package/php/datetime/gettimeofday.js +7 -10
- package/php/datetime/gmdate.js +17 -16
- package/php/datetime/gmmktime.js +23 -25
- package/php/datetime/gmstrftime.js +17 -14
- package/php/datetime/idate.js +44 -38
- package/php/datetime/index.js +15 -18
- package/php/datetime/microtime.js +11 -14
- package/php/datetime/mktime.js +14 -17
- package/php/datetime/strftime.js +122 -113
- package/php/datetime/strptime.js +210 -191
- package/php/datetime/strtotime.js +615 -496
- package/php/datetime/time.js +11 -13
- package/php/exec/escapeshellarg.js +16 -18
- package/php/exec/index.js +1 -4
- package/php/filesystem/basename.js +22 -24
- package/php/filesystem/dirname.js +12 -14
- package/php/filesystem/file_exists.js +9 -11
- package/php/filesystem/file_get_contents.js +3 -6
- package/php/filesystem/index.js +6 -9
- package/php/filesystem/pathinfo.js +47 -46
- package/php/filesystem/realpath.js +16 -19
- package/php/funchand/call_user_func.js +4 -7
- package/php/funchand/call_user_func_array.js +19 -22
- package/php/funchand/create_function.js +4 -7
- package/php/funchand/function_exists.js +4 -8
- package/php/funchand/get_defined_functions.js +25 -32
- package/php/funchand/index.js +5 -8
- package/php/i18n/i18n_loc_get_default.js +7 -10
- package/php/i18n/i18n_loc_set_default.js +12 -15
- package/php/i18n/index.js +2 -5
- package/php/index.js +20 -23
- package/php/info/assert_options.js +25 -27
- package/php/info/getenv.js +8 -10
- package/php/info/index.js +6 -9
- package/php/info/ini_get.js +9 -12
- package/php/info/ini_set.js +32 -34
- package/php/info/set_time_limit.js +8 -11
- package/php/info/version_compare.js +43 -44
- package/php/json/index.js +3 -6
- package/php/json/json_decode.js +42 -28
- package/php/json/json_encode.js +89 -66
- package/php/json/json_last_error.js +11 -13
- package/php/math/abs.js +2 -5
- package/php/math/acos.js +2 -5
- package/php/math/acosh.js +7 -9
- package/php/math/asin.js +2 -5
- package/php/math/asinh.js +7 -9
- package/php/math/atan.js +7 -9
- package/php/math/atan2.js +7 -9
- package/php/math/atanh.js +2 -5
- package/php/math/base_convert.js +8 -10
- package/php/math/bindec.js +12 -14
- package/php/math/ceil.js +7 -9
- package/php/math/cos.js +7 -9
- package/php/math/cosh.js +7 -9
- package/php/math/decbin.js +16 -18
- package/php/math/dechex.js +3 -6
- package/php/math/decoct.js +13 -15
- package/php/math/deg2rad.js +8 -10
- package/php/math/exp.js +7 -9
- package/php/math/expm1.js +9 -11
- package/php/math/floor.js +7 -9
- package/php/math/fmod.js +27 -29
- package/php/math/getrandmax.js +7 -9
- package/php/math/hexdec.js +10 -12
- package/php/math/hypot.js +8 -11
- package/php/math/index.js +46 -49
- package/php/math/is_finite.js +9 -14
- package/php/math/is_infinite.js +9 -14
- package/php/math/is_nan.js +8 -13
- package/php/math/lcg_value.js +8 -10
- package/php/math/log.js +8 -10
- package/php/math/log10.js +12 -14
- package/php/math/log1p.js +15 -17
- package/php/math/max.js +54 -59
- package/php/math/min.js +54 -59
- package/php/math/mt_getrandmax.js +7 -9
- package/php/math/mt_rand.js +15 -17
- package/php/math/octdec.js +8 -10
- package/php/math/pi.js +2 -5
- package/php/math/pow.js +2 -5
- package/php/math/rad2deg.js +8 -10
- package/php/math/rand.js +15 -17
- package/php/math/round.js +48 -49
- package/php/math/sin.js +7 -9
- package/php/math/sinh.js +7 -9
- package/php/math/sqrt.js +7 -9
- package/php/math/tan.js +7 -9
- package/php/math/tanh.js +8 -10
- package/php/misc/index.js +2 -5
- package/php/misc/pack.js +173 -165
- package/php/misc/uniqid.js +20 -23
- package/php/net-gopher/gopher_parsedir.js +27 -29
- package/php/net-gopher/index.js +1 -4
- package/php/network/index.js +6 -9
- package/php/network/inet_ntop.js +15 -15
- package/php/network/inet_pton.js +30 -34
- package/php/network/ip2long.js +25 -15
- package/php/network/long2ip.js +8 -10
- package/php/network/setcookie.js +11 -13
- package/php/network/setrawcookie.js +16 -19
- package/php/pcre/index.js +4 -7
- package/php/pcre/preg_match.js +3 -6
- package/php/pcre/preg_quote.js +2 -5
- package/php/pcre/preg_replace.js +8 -11
- package/php/pcre/sql_regcase.js +17 -20
- package/php/strings/addcslashes.js +86 -88
- package/php/strings/addslashes.js +15 -16
- package/php/strings/bin2hex.js +19 -43
- package/php/strings/chop.js +8 -10
- package/php/strings/chr.js +12 -14
- package/php/strings/chunk_split.js +15 -17
- package/php/strings/convert_cyr_string.js +137 -50
- package/php/strings/convert_uuencode.js +35 -38
- package/php/strings/count_chars.js +29 -27
- package/php/strings/crc32.js +276 -21
- package/php/strings/echo.js +28 -30
- package/php/strings/explode.js +31 -26
- package/php/strings/get_html_translation_table.js +123 -122
- package/php/strings/hex2bin.js +21 -21
- package/php/strings/html_entity_decode.js +31 -33
- package/php/strings/htmlentities.js +38 -34
- package/php/strings/htmlspecialchars.js +20 -23
- package/php/strings/htmlspecialchars_decode.js +19 -21
- package/php/strings/implode.js +23 -27
- package/php/strings/index.js +91 -94
- package/php/strings/join.js +8 -10
- package/php/strings/lcfirst.js +9 -11
- package/php/strings/levenshtein.js +37 -39
- package/php/strings/localeconv.js +12 -15
- package/php/strings/ltrim.js +12 -14
- package/php/strings/md5.js +216 -223
- package/php/strings/md5_file.js +17 -19
- package/php/strings/metaphone.js +112 -117
- package/php/strings/money_format.js +139 -126
- package/php/strings/nl2br.js +24 -26
- package/php/strings/nl_langinfo.js +32 -35
- package/php/strings/number_format.js +19 -22
- package/php/strings/ord.js +19 -21
- package/php/strings/parse_str.js +53 -56
- package/php/strings/printf.js +6 -9
- package/php/strings/quoted_printable_decode.js +7 -10
- package/php/strings/quoted_printable_encode.js +19 -20
- package/php/strings/quotemeta.js +7 -9
- package/php/strings/rtrim.js +14 -16
- package/php/strings/setlocale.js +148 -104
- package/php/strings/sha1.js +108 -106
- package/php/strings/sha1_file.js +15 -17
- package/php/strings/similar_text.js +34 -33
- package/php/strings/soundex.js +34 -36
- package/php/strings/split.js +8 -10
- package/php/strings/sprintf.js +112 -114
- package/php/strings/sscanf.js +99 -96
- package/php/strings/str_getcsv.js +37 -32
- package/php/strings/str_ireplace.js +50 -55
- package/php/strings/str_pad.js +18 -21
- package/php/strings/str_repeat.js +14 -16
- package/php/strings/str_replace.js +32 -37
- package/php/strings/str_rot13.js +15 -17
- package/php/strings/str_shuffle.js +12 -15
- package/php/strings/str_split.js +19 -21
- package/php/strings/str_word_count.js +51 -50
- package/php/strings/strcasecmp.js +12 -14
- package/php/strings/strchr.js +10 -12
- package/php/strings/strcmp.js +12 -14
- package/php/strings/strcoll.js +9 -12
- package/php/strings/strcspn.js +30 -25
- package/php/strings/strip_tags.js +50 -52
- package/php/strings/stripos.js +12 -14
- package/php/strings/stripslashes.js +8 -10
- package/php/strings/stristr.js +15 -17
- package/php/strings/strlen.js +23 -26
- package/php/strings/strnatcasecmp.js +6 -8
- package/php/strings/strnatcmp.js +47 -46
- package/php/strings/strncasecmp.js +30 -32
- package/php/strings/strncmp.js +5 -7
- package/php/strings/strpbrk.js +12 -14
- package/php/strings/strpos.js +11 -13
- package/php/strings/strrchr.js +7 -10
- package/php/strings/strrev.js +188 -10
- package/php/strings/strripos.js +16 -18
- package/php/strings/strrpos.js +20 -22
- package/php/strings/strspn.js +24 -26
- package/php/strings/strstr.js +20 -22
- package/php/strings/strtok.js +14 -16
- package/php/strings/strtolower.js +8 -10
- package/php/strings/strtoupper.js +8 -10
- package/php/strings/strtr.js +38 -43
- package/php/strings/substr.js +14 -18
- package/php/strings/substr_compare.js +18 -20
- package/php/strings/substr_count.js +11 -14
- package/php/strings/substr_replace.js +5 -8
- package/php/strings/trim.js +53 -32
- package/php/strings/ucfirst.js +11 -13
- package/php/strings/ucwords.js +3 -6
- package/php/strings/vprintf.js +6 -9
- package/php/strings/vsprintf.js +8 -10
- package/php/strings/wordwrap.js +32 -35
- package/php/url/base64_decode.js +42 -40
- package/php/url/base64_encode.js +51 -53
- package/php/url/http_build_query.js +27 -32
- package/php/url/index.js +8 -11
- package/php/url/parse_url.js +61 -25
- package/php/url/rawurldecode.js +8 -8
- package/php/url/rawurlencode.js +9 -6
- package/php/url/urldecode.js +9 -8
- package/php/url/urlencode.js +11 -6
- package/php/var/boolval.js +31 -33
- package/php/var/doubleval.js +10 -12
- package/php/var/empty.js +11 -16
- package/php/var/floatval.js +13 -15
- package/php/var/gettype.js +22 -23
- package/php/var/index.js +30 -33
- package/php/var/intval.js +35 -39
- package/php/var/is_array.js +27 -31
- package/php/var/is_binary.js +2 -5
- package/php/var/is_bool.js +10 -12
- package/php/var/is_buffer.js +2 -5
- package/php/var/is_callable.js +34 -35
- package/php/var/is_double.js +10 -12
- package/php/var/is_float.js +12 -14
- package/php/var/is_int.js +20 -22
- package/php/var/is_integer.js +12 -14
- package/php/var/is_long.js +3 -6
- package/php/var/is_null.js +9 -11
- package/php/var/is_numeric.js +30 -6
- package/php/var/is_object.js +4 -9
- package/php/var/is_real.js +3 -6
- package/php/var/is_scalar.js +2 -8
- package/php/var/is_string.js +9 -11
- package/php/var/is_unicode.js +12 -15
- package/php/var/isset.js +9 -12
- package/php/var/print_r.js +49 -53
- package/php/var/serialize.js +47 -52
- package/php/var/serialize.vitest.ts +10 -0
- package/php/var/strval.js +10 -13
- package/php/var/unserialize.js +168 -202
- package/php/var/var_dump.js +105 -104
- package/php/var/var_export.js +64 -66
- package/php/xdiff/index.js +2 -5
- package/php/xdiff/xdiff_string_diff.js +240 -226
- package/php/xdiff/xdiff_string_patch.js +98 -93
- package/php/xml/index.js +2 -5
- package/php/xml/utf8_decode.js +40 -42
- package/php/xml/utf8_encode.js +40 -42
- package/python/index.js +1 -4
- package/python/math/ceil.js +17 -0
- package/python/math/exp.js +12 -0
- package/python/math/fabs.js +14 -0
- package/python/math/factorial.js +29 -0
- package/python/math/floor.js +14 -0
- package/python/math/gcd.js +23 -0
- package/python/math/index.js +15 -0
- package/python/math/isfinite.js +14 -0
- package/python/math/isinf.js +14 -0
- package/python/math/isnan.js +14 -0
- package/python/math/log.js +16 -0
- package/python/math/log10.js +14 -0
- package/python/math/log2.js +14 -0
- package/python/math/pow.js +14 -0
- package/python/math/sqrt.js +14 -0
- package/python/math/trunc.js +14 -0
- package/python/string/ascii_letters.js +14 -14
- package/python/string/ascii_lowercase.js +12 -16
- package/python/string/ascii_uppercase.js +12 -16
- package/python/string/capwords.js +4 -7
- package/python/string/digits.js +10 -0
- package/python/string/hexdigits.js +10 -0
- package/python/string/index.js +10 -8
- package/python/string/octdigits.js +10 -0
- package/python/string/printable.js +15 -0
- package/python/string/punctuation.js +5 -7
- package/python/string/whitespace.js +10 -0
- package/r/base/abs.js +13 -0
- package/r/base/ceiling.js +16 -0
- package/r/base/floor.js +14 -0
- package/r/base/index.js +3 -0
- package/ruby/Array/compact.js +18 -0
- package/ruby/Array/first.js +22 -0
- package/ruby/Array/flatten.js +22 -0
- package/ruby/Array/index.js +6 -0
- package/ruby/Array/last.js +22 -0
- package/ruby/Array/sample.js +31 -0
- package/ruby/Array/uniq.js +16 -0
- package/ruby/Math/acos.js +2 -5
- package/ruby/Math/asin.js +11 -0
- package/ruby/Math/atan.js +11 -0
- package/ruby/Math/cbrt.js +13 -0
- package/ruby/Math/cos.js +12 -0
- package/ruby/Math/cosh.js +11 -0
- package/ruby/Math/exp.js +11 -0
- package/ruby/Math/index.js +15 -4
- package/ruby/Math/log.js +11 -0
- package/ruby/Math/log10.js +13 -0
- package/ruby/Math/log2.js +13 -0
- package/ruby/Math/sin.js +12 -0
- package/ruby/Math/sinh.js +11 -0
- package/ruby/Math/sqrt.js +13 -0
- package/ruby/Math/tan.js +11 -0
- package/ruby/Math/tanh.js +11 -0
- package/ruby/String/capitalize.js +19 -0
- package/ruby/String/chomp.js +27 -0
- package/ruby/String/chop.js +25 -0
- package/ruby/String/downcase.js +10 -0
- package/ruby/String/end_with.js +17 -0
- package/ruby/String/include.js +12 -0
- package/ruby/String/index.js +11 -0
- package/ruby/String/length.js +12 -0
- package/ruby/String/reverse.js +12 -0
- package/ruby/String/start_with.js +14 -0
- package/ruby/String/strip.js +12 -0
- package/ruby/String/upcase.js +10 -0
- package/ruby/index.js +1 -4
- package/_util/cli.js +0 -14
- package/_util/cli.js.map +0 -1
- package/_util/util.js +0 -620
- package/_util/util.js.map +0 -1
- package/c/index.js.map +0 -1
- package/c/math/abs.js.map +0 -1
- package/c/math/frexp.js.map +0 -1
- package/c/math/index.js.map +0 -1
- package/c/stdio/index.js.map +0 -1
- package/c/stdio/sprintf.js.map +0 -1
- package/golang/index.js.map +0 -1
- package/golang/strings/Contains.js.map +0 -1
- package/golang/strings/Count.js.map +0 -1
- package/golang/strings/Index2.js.map +0 -1
- package/golang/strings/LastIndex.js.map +0 -1
- package/golang/strings/index.js.map +0 -1
- package/index.js.map +0 -1
- package/php/_helpers/_bc.js.map +0 -1
- package/php/_helpers/_phpCastString.js.map +0 -1
- package/php/_helpers/_php_cast_float.js.map +0 -1
- package/php/_helpers/_php_cast_int.js.map +0 -1
- package/php/_helpers/index.js.map +0 -1
- package/php/array/array_change_key_case.js.map +0 -1
- package/php/array/array_chunk.js.map +0 -1
- package/php/array/array_column.js.map +0 -1
- package/php/array/array_combine.js.map +0 -1
- package/php/array/array_count_values.js.map +0 -1
- package/php/array/array_diff.js.map +0 -1
- package/php/array/array_diff_assoc.js.map +0 -1
- package/php/array/array_diff_key.js.map +0 -1
- package/php/array/array_diff_uassoc.js.map +0 -1
- package/php/array/array_diff_ukey.js.map +0 -1
- package/php/array/array_fill.js.map +0 -1
- package/php/array/array_fill_keys.js.map +0 -1
- package/php/array/array_filter.js.map +0 -1
- package/php/array/array_flip.js.map +0 -1
- package/php/array/array_intersect.js.map +0 -1
- package/php/array/array_intersect_assoc.js.map +0 -1
- package/php/array/array_intersect_key.js.map +0 -1
- package/php/array/array_intersect_uassoc.js.map +0 -1
- package/php/array/array_intersect_ukey.js.map +0 -1
- package/php/array/array_key_exists.js.map +0 -1
- package/php/array/array_keys.js.map +0 -1
- package/php/array/array_map.js.map +0 -1
- package/php/array/array_merge.js.map +0 -1
- package/php/array/array_merge_recursive.js.map +0 -1
- package/php/array/array_multisort.js.map +0 -1
- package/php/array/array_pad.js.map +0 -1
- package/php/array/array_pop.js.map +0 -1
- package/php/array/array_product.js.map +0 -1
- package/php/array/array_push.js.map +0 -1
- package/php/array/array_rand.js.map +0 -1
- package/php/array/array_reduce.js.map +0 -1
- package/php/array/array_replace.js.map +0 -1
- package/php/array/array_replace_recursive.js.map +0 -1
- package/php/array/array_reverse.js.map +0 -1
- package/php/array/array_search.js.map +0 -1
- package/php/array/array_shift.js.map +0 -1
- package/php/array/array_slice.js.map +0 -1
- package/php/array/array_splice.js.map +0 -1
- package/php/array/array_sum.js.map +0 -1
- package/php/array/array_udiff.js.map +0 -1
- package/php/array/array_udiff_assoc.js.map +0 -1
- package/php/array/array_udiff_uassoc.js.map +0 -1
- package/php/array/array_uintersect.js.map +0 -1
- package/php/array/array_uintersect_uassoc.js.map +0 -1
- package/php/array/array_unique.js.map +0 -1
- package/php/array/array_unshift.js.map +0 -1
- package/php/array/array_values.js.map +0 -1
- package/php/array/array_walk.js.map +0 -1
- package/php/array/array_walk_recursive.js.map +0 -1
- package/php/array/arsort.js.map +0 -1
- package/php/array/asort.js.map +0 -1
- package/php/array/count.js.map +0 -1
- package/php/array/current.js.map +0 -1
- package/php/array/each.js.map +0 -1
- package/php/array/end.js.map +0 -1
- package/php/array/in_array.js.map +0 -1
- package/php/array/index.js.map +0 -1
- package/php/array/key.js.map +0 -1
- package/php/array/krsort.js.map +0 -1
- package/php/array/ksort.js.map +0 -1
- package/php/array/natcasesort.js.map +0 -1
- package/php/array/natsort.js.map +0 -1
- package/php/array/next.js.map +0 -1
- package/php/array/pos.js.map +0 -1
- package/php/array/prev.js.map +0 -1
- package/php/array/range.js.map +0 -1
- package/php/array/reset.js.map +0 -1
- package/php/array/rsort.js.map +0 -1
- package/php/array/shuffle.js.map +0 -1
- package/php/array/sizeof.js.map +0 -1
- package/php/array/sort.js.map +0 -1
- package/php/array/uasort.js.map +0 -1
- package/php/array/uksort.js.map +0 -1
- package/php/array/usort.js.map +0 -1
- package/php/bc/bcadd.js.map +0 -1
- package/php/bc/bccomp.js.map +0 -1
- package/php/bc/bcdiv.js.map +0 -1
- package/php/bc/bcmul.js.map +0 -1
- package/php/bc/bcround.js.map +0 -1
- package/php/bc/bcscale.js.map +0 -1
- package/php/bc/bcsub.js.map +0 -1
- package/php/bc/index.js.map +0 -1
- package/php/ctype/ctype_alnum.js.map +0 -1
- package/php/ctype/ctype_alpha.js.map +0 -1
- package/php/ctype/ctype_cntrl.js.map +0 -1
- package/php/ctype/ctype_digit.js.map +0 -1
- package/php/ctype/ctype_graph.js.map +0 -1
- package/php/ctype/ctype_lower.js.map +0 -1
- package/php/ctype/ctype_print.js.map +0 -1
- package/php/ctype/ctype_punct.js.map +0 -1
- package/php/ctype/ctype_space.js.map +0 -1
- package/php/ctype/ctype_upper.js.map +0 -1
- package/php/ctype/ctype_xdigit.js.map +0 -1
- package/php/ctype/index.js.map +0 -1
- package/php/datetime/checkdate.js.map +0 -1
- package/php/datetime/date.js.map +0 -1
- package/php/datetime/date_parse.js.map +0 -1
- package/php/datetime/getdate.js.map +0 -1
- package/php/datetime/gettimeofday.js.map +0 -1
- package/php/datetime/gmdate.js.map +0 -1
- package/php/datetime/gmmktime.js.map +0 -1
- package/php/datetime/gmstrftime.js.map +0 -1
- package/php/datetime/idate.js.map +0 -1
- package/php/datetime/index.js.map +0 -1
- package/php/datetime/microtime.js.map +0 -1
- package/php/datetime/mktime.js.map +0 -1
- package/php/datetime/strftime.js.map +0 -1
- package/php/datetime/strptime.js.map +0 -1
- package/php/datetime/strtotime.js.map +0 -1
- package/php/datetime/time.js.map +0 -1
- package/php/exec/escapeshellarg.js.map +0 -1
- package/php/exec/index.js.map +0 -1
- package/php/filesystem/basename.js.map +0 -1
- package/php/filesystem/dirname.js.map +0 -1
- package/php/filesystem/file_exists.js.map +0 -1
- package/php/filesystem/file_get_contents.js.map +0 -1
- package/php/filesystem/index.js.map +0 -1
- package/php/filesystem/pathinfo.js.map +0 -1
- package/php/filesystem/realpath.js.map +0 -1
- package/php/funchand/call_user_func.js.map +0 -1
- package/php/funchand/call_user_func_array.js.map +0 -1
- package/php/funchand/create_function.js.map +0 -1
- package/php/funchand/function_exists.js.map +0 -1
- package/php/funchand/get_defined_functions.js.map +0 -1
- package/php/funchand/index.js.map +0 -1
- package/php/i18n/i18n_loc_get_default.js.map +0 -1
- package/php/i18n/i18n_loc_set_default.js.map +0 -1
- package/php/i18n/index.js.map +0 -1
- package/php/index.js.map +0 -1
- package/php/info/assert_options.js.map +0 -1
- package/php/info/getenv.js.map +0 -1
- package/php/info/index.js.map +0 -1
- package/php/info/ini_get.js.map +0 -1
- package/php/info/ini_set.js.map +0 -1
- package/php/info/set_time_limit.js.map +0 -1
- package/php/info/version_compare.js.map +0 -1
- package/php/json/index.js.map +0 -1
- package/php/json/json_decode.js.map +0 -1
- package/php/json/json_encode.js.map +0 -1
- package/php/json/json_last_error.js.map +0 -1
- package/php/math/abs.js.map +0 -1
- package/php/math/acos.js.map +0 -1
- package/php/math/acosh.js.map +0 -1
- package/php/math/asin.js.map +0 -1
- package/php/math/asinh.js.map +0 -1
- package/php/math/atan.js.map +0 -1
- package/php/math/atan2.js.map +0 -1
- package/php/math/atanh.js.map +0 -1
- package/php/math/base_convert.js.map +0 -1
- package/php/math/bindec.js.map +0 -1
- package/php/math/ceil.js.map +0 -1
- package/php/math/cos.js.map +0 -1
- package/php/math/cosh.js.map +0 -1
- package/php/math/decbin.js.map +0 -1
- package/php/math/dechex.js.map +0 -1
- package/php/math/decoct.js.map +0 -1
- package/php/math/deg2rad.js.map +0 -1
- package/php/math/exp.js.map +0 -1
- package/php/math/expm1.js.map +0 -1
- package/php/math/floor.js.map +0 -1
- package/php/math/fmod.js.map +0 -1
- package/php/math/getrandmax.js.map +0 -1
- package/php/math/hexdec.js.map +0 -1
- package/php/math/hypot.js.map +0 -1
- package/php/math/index.js.map +0 -1
- package/php/math/is_finite.js.map +0 -1
- package/php/math/is_infinite.js.map +0 -1
- package/php/math/is_nan.js.map +0 -1
- package/php/math/lcg_value.js.map +0 -1
- package/php/math/log.js.map +0 -1
- package/php/math/log10.js.map +0 -1
- package/php/math/log1p.js.map +0 -1
- package/php/math/max.js.map +0 -1
- package/php/math/min.js.map +0 -1
- package/php/math/mt_getrandmax.js.map +0 -1
- package/php/math/mt_rand.js.map +0 -1
- package/php/math/octdec.js.map +0 -1
- package/php/math/pi.js.map +0 -1
- package/php/math/pow.js.map +0 -1
- package/php/math/rad2deg.js.map +0 -1
- package/php/math/rand.js.map +0 -1
- package/php/math/round.js.map +0 -1
- package/php/math/sin.js.map +0 -1
- package/php/math/sinh.js.map +0 -1
- package/php/math/sqrt.js.map +0 -1
- package/php/math/tan.js.map +0 -1
- package/php/math/tanh.js.map +0 -1
- package/php/misc/index.js.map +0 -1
- package/php/misc/pack.js.map +0 -1
- package/php/misc/uniqid.js.map +0 -1
- package/php/net-gopher/gopher_parsedir.js.map +0 -1
- package/php/net-gopher/index.js.map +0 -1
- package/php/network/index.js.map +0 -1
- package/php/network/inet_ntop.js.map +0 -1
- package/php/network/inet_pton.js.map +0 -1
- package/php/network/ip2long.js.map +0 -1
- package/php/network/long2ip.js.map +0 -1
- package/php/network/setcookie.js.map +0 -1
- package/php/network/setrawcookie.js.map +0 -1
- package/php/pcre/index.js.map +0 -1
- package/php/pcre/preg_match.js.map +0 -1
- package/php/pcre/preg_quote.js.map +0 -1
- package/php/pcre/preg_replace.js.map +0 -1
- package/php/pcre/sql_regcase.js.map +0 -1
- package/php/strings/addcslashes.js.map +0 -1
- package/php/strings/addslashes.js.map +0 -1
- package/php/strings/bin2hex.js.map +0 -1
- package/php/strings/chop.js.map +0 -1
- package/php/strings/chr.js.map +0 -1
- package/php/strings/chunk_split.js.map +0 -1
- package/php/strings/convert_cyr_string.js.map +0 -1
- package/php/strings/convert_uuencode.js.map +0 -1
- package/php/strings/count_chars.js.map +0 -1
- package/php/strings/crc32.js.map +0 -1
- package/php/strings/echo.js.map +0 -1
- package/php/strings/explode.js.map +0 -1
- package/php/strings/get_html_translation_table.js.map +0 -1
- package/php/strings/hex2bin.js.map +0 -1
- package/php/strings/html_entity_decode.js.map +0 -1
- package/php/strings/htmlentities.js.map +0 -1
- package/php/strings/htmlspecialchars.js.map +0 -1
- package/php/strings/htmlspecialchars_decode.js.map +0 -1
- package/php/strings/implode.js.map +0 -1
- package/php/strings/index.js.map +0 -1
- package/php/strings/join.js.map +0 -1
- package/php/strings/lcfirst.js.map +0 -1
- package/php/strings/levenshtein.js.map +0 -1
- package/php/strings/localeconv.js.map +0 -1
- package/php/strings/ltrim.js.map +0 -1
- package/php/strings/md5.js.map +0 -1
- package/php/strings/md5_file.js.map +0 -1
- package/php/strings/metaphone.js.map +0 -1
- package/php/strings/money_format.js.map +0 -1
- package/php/strings/nl2br.js.map +0 -1
- package/php/strings/nl_langinfo.js.map +0 -1
- package/php/strings/number_format.js.map +0 -1
- package/php/strings/ord.js.map +0 -1
- package/php/strings/parse_str.js.map +0 -1
- package/php/strings/printf.js.map +0 -1
- package/php/strings/quoted_printable_decode.js.map +0 -1
- package/php/strings/quoted_printable_encode.js.map +0 -1
- package/php/strings/quotemeta.js.map +0 -1
- package/php/strings/rtrim.js.map +0 -1
- package/php/strings/setlocale.js.map +0 -1
- package/php/strings/sha1.js.map +0 -1
- package/php/strings/sha1_file.js.map +0 -1
- package/php/strings/similar_text.js.map +0 -1
- package/php/strings/soundex.js.map +0 -1
- package/php/strings/split.js.map +0 -1
- package/php/strings/sprintf.js.map +0 -1
- package/php/strings/sscanf.js.map +0 -1
- package/php/strings/str_getcsv.js.map +0 -1
- package/php/strings/str_ireplace.js.map +0 -1
- package/php/strings/str_pad.js.map +0 -1
- package/php/strings/str_repeat.js.map +0 -1
- package/php/strings/str_replace.js.map +0 -1
- package/php/strings/str_rot13.js.map +0 -1
- package/php/strings/str_shuffle.js.map +0 -1
- package/php/strings/str_split.js.map +0 -1
- package/php/strings/str_word_count.js.map +0 -1
- package/php/strings/strcasecmp.js.map +0 -1
- package/php/strings/strchr.js.map +0 -1
- package/php/strings/strcmp.js.map +0 -1
- package/php/strings/strcoll.js.map +0 -1
- package/php/strings/strcspn.js.map +0 -1
- package/php/strings/strip_tags.js.map +0 -1
- package/php/strings/stripos.js.map +0 -1
- package/php/strings/stripslashes.js.map +0 -1
- package/php/strings/stristr.js.map +0 -1
- package/php/strings/strlen.js.map +0 -1
- package/php/strings/strnatcasecmp.js.map +0 -1
- package/php/strings/strnatcmp.js.map +0 -1
- package/php/strings/strncasecmp.js.map +0 -1
- package/php/strings/strncmp.js.map +0 -1
- package/php/strings/strpbrk.js.map +0 -1
- package/php/strings/strpos.js.map +0 -1
- package/php/strings/strrchr.js.map +0 -1
- package/php/strings/strrev.js.map +0 -1
- package/php/strings/strripos.js.map +0 -1
- package/php/strings/strrpos.js.map +0 -1
- package/php/strings/strspn.js.map +0 -1
- package/php/strings/strstr.js.map +0 -1
- package/php/strings/strtok.js.map +0 -1
- package/php/strings/strtolower.js.map +0 -1
- package/php/strings/strtoupper.js.map +0 -1
- package/php/strings/strtr.js.map +0 -1
- package/php/strings/substr.js.map +0 -1
- package/php/strings/substr_compare.js.map +0 -1
- package/php/strings/substr_count.js.map +0 -1
- package/php/strings/substr_replace.js.map +0 -1
- package/php/strings/trim.js.map +0 -1
- package/php/strings/ucfirst.js.map +0 -1
- package/php/strings/ucwords.js.map +0 -1
- package/php/strings/vprintf.js.map +0 -1
- package/php/strings/vsprintf.js.map +0 -1
- package/php/strings/wordwrap.js.map +0 -1
- package/php/url/base64_decode.js.map +0 -1
- package/php/url/base64_encode.js.map +0 -1
- package/php/url/http_build_query.js.map +0 -1
- package/php/url/index.js.map +0 -1
- package/php/url/parse_url.js.map +0 -1
- package/php/url/rawurldecode.js.map +0 -1
- package/php/url/rawurlencode.js.map +0 -1
- package/php/url/urldecode.js.map +0 -1
- package/php/url/urlencode.js.map +0 -1
- package/php/var/boolval.js.map +0 -1
- package/php/var/doubleval.js.map +0 -1
- package/php/var/empty.js.map +0 -1
- package/php/var/floatval.js.map +0 -1
- package/php/var/gettype.js.map +0 -1
- package/php/var/index.js.map +0 -1
- package/php/var/intval.js.map +0 -1
- package/php/var/is_array.js.map +0 -1
- package/php/var/is_binary.js.map +0 -1
- package/php/var/is_bool.js.map +0 -1
- package/php/var/is_buffer.js.map +0 -1
- package/php/var/is_callable.js.map +0 -1
- package/php/var/is_double.js.map +0 -1
- package/php/var/is_float.js.map +0 -1
- package/php/var/is_int.js.map +0 -1
- package/php/var/is_integer.js.map +0 -1
- package/php/var/is_long.js.map +0 -1
- package/php/var/is_null.js.map +0 -1
- package/php/var/is_numeric.js.map +0 -1
- package/php/var/is_object.js.map +0 -1
- package/php/var/is_real.js.map +0 -1
- package/php/var/is_scalar.js.map +0 -1
- package/php/var/is_string.js.map +0 -1
- package/php/var/is_unicode.js.map +0 -1
- package/php/var/isset.js.map +0 -1
- package/php/var/print_r.js.map +0 -1
- package/php/var/serialize.js.map +0 -1
- package/php/var/serialize.mocha.js +0 -14
- package/php/var/serialize.mocha.js.map +0 -1
- package/php/var/strval.js.map +0 -1
- package/php/var/unserialize.js.map +0 -1
- package/php/var/var_dump.js.map +0 -1
- package/php/var/var_export.js.map +0 -1
- package/php/xdiff/index.js.map +0 -1
- package/php/xdiff/xdiff_string_diff.js.map +0 -1
- package/php/xdiff/xdiff_string_patch.js.map +0 -1
- package/php/xml/index.js.map +0 -1
- package/php/xml/utf8_decode.js.map +0 -1
- package/php/xml/utf8_encode.js.map +0 -1
- package/python/index.js.map +0 -1
- package/python/string/ascii_letters.js.map +0 -1
- package/python/string/ascii_lowercase.js.map +0 -1
- package/python/string/ascii_uppercase.js.map +0 -1
- package/python/string/capwords.js.map +0 -1
- package/python/string/index.js.map +0 -1
- package/python/string/punctuation.js.map +0 -1
- package/ruby/Math/acos.js.map +0 -1
- package/ruby/Math/index.js.map +0 -1
- package/ruby/index.js.map +0 -1
package/php/strings/sscanf.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
module.exports = function sscanf(str, format) {
|
|
4
2
|
// discuss at: https://locutus.io/php/sscanf/
|
|
5
3
|
// original by: Brett Zamir (https://brett-zamir.me)
|
|
@@ -12,12 +10,12 @@ module.exports = function sscanf(str, format) {
|
|
|
12
10
|
// example 3: sscanf("10--20", "%2$d--%1$d") // Must escape '$' in PHP, but not JS
|
|
13
11
|
// returns 3: [20, 10]
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
const retArr = []
|
|
14
|
+
const _NWS = /\S/
|
|
15
|
+
const args = arguments
|
|
16
|
+
let digit
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
const _setExtraConversionSpecs = function (offset) {
|
|
21
19
|
// Since a mismatched character sets us off track from future
|
|
22
20
|
// legitimate finds, we just scan
|
|
23
21
|
// to the end for any other conversion specifications (besides a percent literal),
|
|
@@ -27,84 +25,89 @@ module.exports = function sscanf(str, format) {
|
|
|
27
25
|
// Do not allow % in last char. class
|
|
28
26
|
// var matches = format.match(/%[+-]?([ 0]|'.)?-?\d*(\.\d+)?[bcdeufFosxX]/g);
|
|
29
27
|
// Do not allow % in last char. class:
|
|
30
|
-
|
|
28
|
+
const matches = format.slice(offset).match(/%[cdeEufgosxX]/g)
|
|
31
29
|
// b, F,G give errors in PHP, but 'g', though also disallowed, doesn't
|
|
32
30
|
if (matches) {
|
|
33
|
-
|
|
31
|
+
let lgth = matches.length
|
|
34
32
|
while (lgth--) {
|
|
35
|
-
retArr.push(null)
|
|
33
|
+
retArr.push(null)
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
|
-
return _finish()
|
|
39
|
-
}
|
|
36
|
+
return _finish()
|
|
37
|
+
}
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
const _finish = function () {
|
|
42
40
|
if (args.length === 2) {
|
|
43
|
-
return retArr
|
|
41
|
+
return retArr
|
|
44
42
|
}
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
let i = 0
|
|
44
|
+
for (; i < retArr.length; ++i) {
|
|
45
|
+
args[i + 2].value = retArr[i]
|
|
47
46
|
}
|
|
48
|
-
return i
|
|
49
|
-
}
|
|
47
|
+
return i
|
|
48
|
+
}
|
|
50
49
|
|
|
51
|
-
|
|
50
|
+
const _addNext = function (j, regex, cb) {
|
|
52
51
|
if (assign) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const remaining = str.slice(j)
|
|
53
|
+
const check = width ? remaining.substr(0, width) : remaining
|
|
54
|
+
const match = regex.exec(check)
|
|
56
55
|
// @todo: Make this more readable
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
const key = digit !== undefined ? digit : retArr.length
|
|
57
|
+
const testNull = (retArr[key] = match ? (cb ? cb.apply(null, match) : match[0]) : null)
|
|
59
58
|
if (testNull === null) {
|
|
60
|
-
throw new Error('No match in string')
|
|
59
|
+
throw new Error('No match in string')
|
|
61
60
|
}
|
|
62
|
-
return j + match[0].length
|
|
61
|
+
return j + match[0].length
|
|
63
62
|
}
|
|
64
|
-
return j
|
|
65
|
-
}
|
|
63
|
+
return j
|
|
64
|
+
}
|
|
66
65
|
|
|
67
66
|
if (arguments.length < 2) {
|
|
68
|
-
throw new Error('Not enough arguments passed to sscanf')
|
|
67
|
+
throw new Error('Not enough arguments passed to sscanf')
|
|
69
68
|
}
|
|
70
69
|
|
|
70
|
+
// These need to be in outer scope for _addNext closure
|
|
71
|
+
let width = 0
|
|
72
|
+
let assign = true
|
|
73
|
+
|
|
71
74
|
// PROCESS
|
|
72
|
-
for (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
for (let i = 0, j = 0; i < format.length; i++) {
|
|
76
|
+
width = 0
|
|
77
|
+
assign = true
|
|
75
78
|
|
|
76
79
|
if (format.charAt(i) === '%') {
|
|
77
80
|
if (format.charAt(i + 1) === '%') {
|
|
78
81
|
if (str.charAt(j) === '%') {
|
|
79
82
|
// a matched percent literal
|
|
80
83
|
// skip beyond duplicated percent
|
|
81
|
-
++i
|
|
82
|
-
++j
|
|
83
|
-
continue
|
|
84
|
+
++i
|
|
85
|
+
++j
|
|
86
|
+
continue
|
|
84
87
|
}
|
|
85
88
|
// Format indicated a percent literal, but not actually present
|
|
86
|
-
return _setExtraConversionSpecs(i + 2)
|
|
89
|
+
return _setExtraConversionSpecs(i + 2)
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
// CHARACTER FOLLOWING PERCENT IS NOT A PERCENT
|
|
90
93
|
|
|
91
94
|
// We need 'g' set to get lastIndex
|
|
92
|
-
|
|
95
|
+
const prePattern = /^(?:(\d+)\$)?(\*)?(\d*)([hlL]?)/g
|
|
93
96
|
|
|
94
|
-
|
|
97
|
+
const preConvs = prePattern.exec(format.slice(i + 1))
|
|
95
98
|
|
|
96
|
-
|
|
99
|
+
const tmpDigit = digit
|
|
97
100
|
if (tmpDigit && preConvs[1] === undefined) {
|
|
98
|
-
|
|
99
|
-
msg += 'any have already been used'
|
|
100
|
-
throw new Error(msg)
|
|
101
|
+
let msg = 'All groups in sscanf() must be expressed as numeric if '
|
|
102
|
+
msg += 'any have already been used'
|
|
103
|
+
throw new Error(msg)
|
|
101
104
|
}
|
|
102
|
-
digit = preConvs[1] ? parseInt(preConvs[1], 10) - 1 : undefined
|
|
105
|
+
digit = preConvs[1] ? parseInt(preConvs[1], 10) - 1 : undefined
|
|
103
106
|
|
|
104
|
-
assign = !preConvs[2]
|
|
105
|
-
width = parseInt(preConvs[3], 10)
|
|
106
|
-
|
|
107
|
-
i += prePattern.lastIndex
|
|
107
|
+
assign = !preConvs[2]
|
|
108
|
+
width = parseInt(preConvs[3], 10)
|
|
109
|
+
const sizeCode = preConvs[4]
|
|
110
|
+
i += prePattern.lastIndex
|
|
108
111
|
|
|
109
112
|
// @todo: Does PHP do anything with these? Seems not to matter
|
|
110
113
|
if (sizeCode) {
|
|
@@ -117,9 +120,9 @@ module.exports = function sscanf(str, format) {
|
|
|
117
120
|
// Treats subsequent as long int (for d,i,n), or unsigned long int (for o,u,x);
|
|
118
121
|
// or as double (for e,f,g) instead of float or wchar_t instead of char
|
|
119
122
|
// Treats subsequent as long double (for e,f,g)
|
|
120
|
-
break
|
|
123
|
+
break
|
|
121
124
|
default:
|
|
122
|
-
throw new Error('Unexpected size specifier in sscanf()!')
|
|
125
|
+
throw new Error('Unexpected size specifier in sscanf()!')
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
// PROCESS CHARACTER
|
|
@@ -133,55 +136,56 @@ module.exports = function sscanf(str, format) {
|
|
|
133
136
|
// Not supported in PHP sscanf; the argument is treated as a float, and
|
|
134
137
|
// presented as a floating-point number (non-locale aware)
|
|
135
138
|
// sscanf doesn't support locales, so no need for two (see %f)
|
|
136
|
-
break
|
|
139
|
+
break
|
|
137
140
|
case 'g':
|
|
138
141
|
// Not supported in PHP sscanf; shorter of %e and %f
|
|
139
142
|
// Irrelevant to input conversion
|
|
140
|
-
break
|
|
143
|
+
break
|
|
141
144
|
case 'G':
|
|
142
145
|
// Not supported in PHP sscanf; shorter of %E and %f
|
|
143
146
|
// Irrelevant to input conversion
|
|
144
|
-
break
|
|
147
|
+
break
|
|
145
148
|
case 'b':
|
|
146
149
|
// Not supported in PHP sscanf; the argument is treated as an integer,
|
|
147
150
|
// and presented as a binary number
|
|
148
151
|
// Not supported - couldn't distinguish from other integers
|
|
149
|
-
break
|
|
150
|
-
case 'i':
|
|
152
|
+
break
|
|
153
|
+
case 'i': {
|
|
151
154
|
// Integer with base detection (Equivalent of 'd', but base 0 instead of 10)
|
|
152
|
-
|
|
155
|
+
const pattern = /([+-])?(?:(?:0x([\da-fA-F]+))|(?:0([0-7]+))|(\d+))/
|
|
153
156
|
j = _addNext(j, pattern, function (num, sign, hex, oct, dec) {
|
|
154
|
-
return hex ? parseInt(num, 16) : oct ? parseInt(num, 8) : parseInt(num, 10)
|
|
155
|
-
})
|
|
156
|
-
break
|
|
157
|
+
return hex ? parseInt(num, 16) : oct ? parseInt(num, 8) : parseInt(num, 10)
|
|
158
|
+
})
|
|
159
|
+
break
|
|
160
|
+
}
|
|
157
161
|
case 'n':
|
|
158
162
|
// Number of characters processed so far
|
|
159
|
-
retArr[digit !== undefined ? digit : retArr.length - 1] = j
|
|
160
|
-
break
|
|
163
|
+
retArr[digit !== undefined ? digit : retArr.length - 1] = j
|
|
164
|
+
break
|
|
161
165
|
// DOCUMENTED UNDER SPRINTF
|
|
162
166
|
case 'c':
|
|
163
167
|
// Get character; suppresses skipping over whitespace!
|
|
164
168
|
// (but shouldn't be whitespace in format anyways, so no difference here)
|
|
165
169
|
// Non-greedy match
|
|
166
|
-
j = _addNext(j, new RegExp('.{1,' + (width || 1) + '}'))
|
|
167
|
-
break
|
|
170
|
+
j = _addNext(j, new RegExp('.{1,' + (width || 1) + '}'))
|
|
171
|
+
break
|
|
168
172
|
case 'D':
|
|
169
173
|
case 'd':
|
|
170
174
|
// sscanf documented decimal number; equivalent of 'd';
|
|
171
175
|
// Optionally signed decimal integer
|
|
172
176
|
j = _addNext(j, /([+-])?(?:0*)(\d+)/, function (num, sign, dec) {
|
|
173
177
|
// Ignores initial zeroes, unlike %i and parseInt()
|
|
174
|
-
|
|
178
|
+
const decInt = parseInt((sign || '') + dec, 10)
|
|
175
179
|
if (decInt < 0) {
|
|
176
180
|
// PHP also won't allow less than -2147483648
|
|
177
181
|
// integer overflow with negative
|
|
178
|
-
return decInt < -2147483648 ? -2147483648 : decInt
|
|
182
|
+
return decInt < -2147483648 ? -2147483648 : decInt
|
|
179
183
|
} else {
|
|
180
184
|
// PHP also won't allow greater than -2147483647
|
|
181
|
-
return decInt < 2147483647 ? decInt : 2147483647
|
|
185
|
+
return decInt < 2147483647 ? decInt : 2147483647
|
|
182
186
|
}
|
|
183
|
-
})
|
|
184
|
-
break
|
|
187
|
+
})
|
|
188
|
+
break
|
|
185
189
|
case 'f':
|
|
186
190
|
case 'E':
|
|
187
191
|
case 'e':
|
|
@@ -190,79 +194,78 @@ module.exports = function sscanf(str, format) {
|
|
|
190
194
|
// These don't discriminate here as both allow exponential float of either case
|
|
191
195
|
j = _addNext(j, /([+-])?(?:0*)(\d*\.?\d*(?:[eE]?\d+)?)/, function (num, sign, dec) {
|
|
192
196
|
if (dec === '.') {
|
|
193
|
-
return null
|
|
197
|
+
return null
|
|
194
198
|
}
|
|
195
199
|
// Ignores initial zeroes, unlike %i and parseFloat()
|
|
196
|
-
return parseFloat((sign || '') + dec)
|
|
197
|
-
})
|
|
198
|
-
break
|
|
200
|
+
return parseFloat((sign || '') + dec)
|
|
201
|
+
})
|
|
202
|
+
break
|
|
199
203
|
case 'u':
|
|
200
204
|
// unsigned decimal integer
|
|
201
205
|
// We won't deal with integer overflows due to signs
|
|
202
206
|
j = _addNext(j, /([+-])?(?:0*)(\d+)/, function (num, sign, dec) {
|
|
203
207
|
// Ignores initial zeroes, unlike %i and parseInt()
|
|
204
|
-
|
|
208
|
+
const decInt = parseInt(dec, 10)
|
|
205
209
|
if (sign === '-') {
|
|
206
210
|
// PHP also won't allow greater than 4294967295
|
|
207
211
|
// integer overflow with negative
|
|
208
|
-
return 4294967296 - decInt
|
|
212
|
+
return 4294967296 - decInt
|
|
209
213
|
} else {
|
|
210
|
-
return decInt < 4294967295 ? decInt : 4294967295
|
|
214
|
+
return decInt < 4294967295 ? decInt : 4294967295
|
|
211
215
|
}
|
|
212
|
-
})
|
|
213
|
-
break
|
|
216
|
+
})
|
|
217
|
+
break
|
|
214
218
|
case 'o':
|
|
215
219
|
// Octal integer // @todo: add overflows as above?
|
|
216
220
|
j = _addNext(j, /([+-])?(?:0([0-7]+))/, function (num, sign, oct) {
|
|
217
|
-
return parseInt(num, 8)
|
|
218
|
-
})
|
|
219
|
-
break
|
|
221
|
+
return parseInt(num, 8)
|
|
222
|
+
})
|
|
223
|
+
break
|
|
220
224
|
case 's':
|
|
221
225
|
// Greedy match
|
|
222
|
-
j = _addNext(j, /\S+/)
|
|
223
|
-
break
|
|
226
|
+
j = _addNext(j, /\S+/)
|
|
227
|
+
break
|
|
224
228
|
case 'X':
|
|
225
229
|
case 'x':
|
|
226
230
|
// Same as 'x'?
|
|
227
231
|
// @todo: add overflows as above?
|
|
228
232
|
// Initial 0x not necessary here
|
|
229
233
|
j = _addNext(j, /([+-])?(?:(?:0x)?([\da-fA-F]+))/, function (num, sign, hex) {
|
|
230
|
-
return parseInt(num, 16)
|
|
231
|
-
})
|
|
232
|
-
break
|
|
234
|
+
return parseInt(num, 16)
|
|
235
|
+
})
|
|
236
|
+
break
|
|
233
237
|
case '':
|
|
234
238
|
// If no character left in expression
|
|
235
|
-
throw new Error('Missing character after percent mark in sscanf() format argument')
|
|
239
|
+
throw new Error('Missing character after percent mark in sscanf() format argument')
|
|
236
240
|
default:
|
|
237
|
-
throw new Error('Unrecognized character after percent mark in sscanf() format argument')
|
|
241
|
+
throw new Error('Unrecognized character after percent mark in sscanf() format argument')
|
|
238
242
|
}
|
|
239
243
|
} catch (e) {
|
|
240
244
|
if (e === 'No match in string') {
|
|
241
245
|
// Allow us to exit
|
|
242
|
-
return _setExtraConversionSpecs(i + 2)
|
|
246
|
+
return _setExtraConversionSpecs(i + 2)
|
|
243
247
|
}
|
|
244
248
|
// Calculate skipping beyond initial percent too
|
|
245
249
|
}
|
|
246
|
-
++i
|
|
250
|
+
++i
|
|
247
251
|
} else if (format.charAt(i) !== str.charAt(j)) {
|
|
248
252
|
// @todo: Double-check i whitespace ignored in string and/or formats
|
|
249
|
-
_NWS.lastIndex = 0
|
|
253
|
+
_NWS.lastIndex = 0
|
|
250
254
|
if (_NWS.test(str.charAt(j)) || str.charAt(j) === '') {
|
|
251
255
|
// Whitespace doesn't need to be an exact match)
|
|
252
|
-
return _setExtraConversionSpecs(i + 1)
|
|
256
|
+
return _setExtraConversionSpecs(i + 1)
|
|
253
257
|
} else {
|
|
254
258
|
// Adjust strings when encounter non-matching whitespace,
|
|
255
259
|
// so they align in future checks above
|
|
256
260
|
// Ok to replace with j++;?
|
|
257
|
-
str = str.slice(0, j) + str.slice(j + 1)
|
|
258
|
-
i
|
|
261
|
+
str = str.slice(0, j) + str.slice(j + 1)
|
|
262
|
+
i--
|
|
259
263
|
}
|
|
260
264
|
} else {
|
|
261
|
-
j
|
|
265
|
+
j++
|
|
262
266
|
}
|
|
263
267
|
}
|
|
264
268
|
|
|
265
269
|
// POST-PROCESSING
|
|
266
|
-
return _finish()
|
|
267
|
-
}
|
|
268
|
-
//# sourceMappingURL=sscanf.js.map
|
|
270
|
+
return _finish()
|
|
271
|
+
}
|
|
@@ -1,54 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// biome-ignore lint/suspicious/noShadowRestrictedNames: escape is PHP parameter name
|
|
3
2
|
module.exports = function str_getcsv(input, delimiter, enclosure, escape) {
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
3
|
+
// discuss at: https://locutus.io/php/str_getcsv/
|
|
4
|
+
// parity verified: PHP 8.3
|
|
5
|
+
// original by: Brett Zamir (https://brett-zamir.me)
|
|
6
|
+
// example 1: str_getcsv('"abc","def","ghi"')
|
|
7
|
+
// returns 1: ['abc', 'def', 'ghi']
|
|
8
|
+
// example 2: str_getcsv('"row2""cell1","row2cell2","row2cell3"', null, null, '"')
|
|
9
|
+
// returns 2: ['row2"cell1', 'row2cell2', 'row2cell3']
|
|
10
10
|
|
|
11
11
|
/*
|
|
12
12
|
// These test cases allowing for missing delimiters are not currently supported
|
|
13
13
|
str_getcsv('"row2""cell1",row2cell2,row2cell3', null, null, '"');
|
|
14
14
|
['row2"cell1', 'row2cell2', 'row2cell3']
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
str_getcsv('row1cell1,"row1,cell2",row1cell3', null, null, '"');
|
|
16
17
|
['row1cell1', 'row1,cell2', 'row1cell3']
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
str_getcsv('"row2""cell1",row2cell2,"row2""""cell3"');
|
|
18
20
|
['row2"cell1', 'row2cell2', 'row2""cell3']
|
|
19
|
-
|
|
21
|
+
|
|
22
|
+
str_getcsv('row1cell1,"row1,cell2","row1"",""cell3"', null, null, '"');
|
|
20
23
|
['row1cell1', 'row1,cell2', 'row1","cell3'];
|
|
21
|
-
|
|
24
|
+
|
|
25
|
+
Should also test newlines within
|
|
22
26
|
*/
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
let i
|
|
29
|
+
let inpLen
|
|
30
|
+
const output = []
|
|
31
|
+
const _backwards = function (str) {
|
|
28
32
|
// We need to go backwards to simulate negative look-behind (don't split on
|
|
29
33
|
// an escaped enclosure even if followed by the delimiter and another enclosure mark)
|
|
30
|
-
return str.split('').reverse().join('')
|
|
31
|
-
}
|
|
32
|
-
|
|
34
|
+
return str.split('').reverse().join('')
|
|
35
|
+
}
|
|
36
|
+
const _pq = function (str) {
|
|
33
37
|
// preg_quote()
|
|
34
|
-
return String(str).replace(/([\\.+*?[^\]$(){}=!<>|:])/g, '\\$1')
|
|
35
|
-
}
|
|
38
|
+
return String(str).replace(/([\\.+*?[^\]$(){}=!<>|:])/g, '\\$1')
|
|
39
|
+
}
|
|
36
40
|
|
|
37
|
-
delimiter = delimiter || ','
|
|
38
|
-
enclosure = enclosure || '"'
|
|
39
|
-
escape = escape || '\\'
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
delimiter = delimiter || ','
|
|
42
|
+
enclosure = enclosure || '"'
|
|
43
|
+
escape = escape || '\\'
|
|
44
|
+
const pqEnc = _pq(enclosure)
|
|
45
|
+
const pqEsc = _pq(escape)
|
|
42
46
|
|
|
43
|
-
input = input.replace(new RegExp('^\\s*' + pqEnc), '').replace(new RegExp(pqEnc + '\\s*$'), '')
|
|
47
|
+
input = input.replace(new RegExp('^\\s*' + pqEnc), '').replace(new RegExp(pqEnc + '\\s*$'), '')
|
|
44
48
|
|
|
45
49
|
// PHP behavior may differ by including whitespace even outside of the enclosure
|
|
46
|
-
input = _backwards(input)
|
|
50
|
+
input = _backwards(input)
|
|
51
|
+
.split(new RegExp(pqEnc + '\\s*' + _pq(delimiter) + '\\s*' + pqEnc + '(?!' + pqEsc + ')', 'g'))
|
|
52
|
+
.reverse()
|
|
47
53
|
|
|
48
54
|
for (i = 0, inpLen = input.length; i < inpLen; i++) {
|
|
49
|
-
output.push(_backwards(input[i]).replace(new RegExp(pqEsc + pqEnc, 'g'), enclosure))
|
|
55
|
+
output.push(_backwards(input[i]).replace(new RegExp(pqEsc + pqEnc, 'g'), enclosure))
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
return output
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=str_getcsv.js.map
|
|
58
|
+
return output
|
|
59
|
+
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
4
|
-
|
|
5
1
|
module.exports = function str_ireplace(search, replace, subject, countObj) {
|
|
6
2
|
// discuss at: https://locutus.io/php/str_ireplace/
|
|
7
3
|
// original by: Glen Arason (https://CanadianDomainRegistry.ca)
|
|
@@ -20,88 +16,87 @@ module.exports = function str_ireplace(search, replace, subject, countObj) {
|
|
|
20
16
|
// example 3: str_ireplace('', '.', 'aaa')
|
|
21
17
|
// returns 3: 'aaa'
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
19
|
+
let i = 0
|
|
20
|
+
let j = 0
|
|
21
|
+
let temp = ''
|
|
22
|
+
let repl = ''
|
|
23
|
+
let sl = 0
|
|
24
|
+
let fl = 0
|
|
25
|
+
let f = ''
|
|
26
|
+
let r = ''
|
|
27
|
+
let s = ''
|
|
28
|
+
let ra = ''
|
|
29
|
+
let otemp = ''
|
|
30
|
+
let oi = ''
|
|
31
|
+
let ofjl = ''
|
|
32
|
+
let os = subject
|
|
33
|
+
const osa = Array.isArray(os)
|
|
38
34
|
// var sa = ''
|
|
39
35
|
|
|
40
|
-
if (
|
|
41
|
-
temp = search
|
|
42
|
-
search = []
|
|
36
|
+
if (typeof search === 'object') {
|
|
37
|
+
temp = search
|
|
38
|
+
search = []
|
|
43
39
|
for (i = 0; i < temp.length; i += 1) {
|
|
44
|
-
search[i] = temp[i].toLowerCase()
|
|
40
|
+
search[i] = temp[i].toLowerCase()
|
|
45
41
|
}
|
|
46
42
|
} else {
|
|
47
|
-
search = search.toLowerCase()
|
|
43
|
+
search = search.toLowerCase()
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
if (
|
|
51
|
-
temp = subject
|
|
52
|
-
subject = []
|
|
46
|
+
if (typeof subject === 'object') {
|
|
47
|
+
temp = subject
|
|
48
|
+
subject = []
|
|
53
49
|
for (i = 0; i < temp.length; i += 1) {
|
|
54
|
-
subject[i] = temp[i].toLowerCase()
|
|
50
|
+
subject[i] = temp[i].toLowerCase()
|
|
55
51
|
}
|
|
56
52
|
} else {
|
|
57
|
-
subject = subject.toLowerCase()
|
|
53
|
+
subject = subject.toLowerCase()
|
|
58
54
|
}
|
|
59
55
|
|
|
60
|
-
if (
|
|
61
|
-
temp = replace
|
|
62
|
-
replace = []
|
|
56
|
+
if (typeof search === 'object' && typeof replace === 'string') {
|
|
57
|
+
temp = replace
|
|
58
|
+
replace = []
|
|
63
59
|
for (i = 0; i < search.length; i += 1) {
|
|
64
|
-
replace[i] = temp
|
|
60
|
+
replace[i] = temp
|
|
65
61
|
}
|
|
66
62
|
}
|
|
67
63
|
|
|
68
|
-
temp = ''
|
|
69
|
-
f = [].concat(search)
|
|
70
|
-
r = [].concat(replace)
|
|
71
|
-
ra =
|
|
72
|
-
s = subject
|
|
73
|
-
// sa =
|
|
74
|
-
s = [].concat(s)
|
|
75
|
-
os = [].concat(os)
|
|
64
|
+
temp = ''
|
|
65
|
+
f = [].concat(search)
|
|
66
|
+
r = [].concat(replace)
|
|
67
|
+
ra = Array.isArray(r)
|
|
68
|
+
s = subject
|
|
69
|
+
// sa = Array.isArray(s)
|
|
70
|
+
s = [].concat(s)
|
|
71
|
+
os = [].concat(os)
|
|
76
72
|
|
|
77
73
|
if (countObj) {
|
|
78
|
-
countObj.value = 0
|
|
74
|
+
countObj.value = 0
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
for (i = 0, sl = s.length; i < sl; i++) {
|
|
82
78
|
if (s[i] === '') {
|
|
83
|
-
continue
|
|
79
|
+
continue
|
|
84
80
|
}
|
|
85
81
|
for (j = 0, fl = f.length; j < fl; j++) {
|
|
86
82
|
if (f[j] === '') {
|
|
87
|
-
continue
|
|
83
|
+
continue
|
|
88
84
|
}
|
|
89
|
-
temp = s[i] + ''
|
|
90
|
-
repl = ra ? r[j] !== undefined ? r[j] : '' : r[0]
|
|
91
|
-
s[i] = temp.split(f[j]).join(repl)
|
|
92
|
-
otemp = os[i] + ''
|
|
93
|
-
oi = temp.indexOf(f[j])
|
|
94
|
-
ofjl = f[j].length
|
|
85
|
+
temp = s[i] + ''
|
|
86
|
+
repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0]
|
|
87
|
+
s[i] = temp.split(f[j]).join(repl)
|
|
88
|
+
otemp = os[i] + ''
|
|
89
|
+
oi = temp.indexOf(f[j])
|
|
90
|
+
ofjl = f[j].length
|
|
95
91
|
if (oi >= 0) {
|
|
96
|
-
os[i] = otemp.split(otemp.substr(oi, ofjl)).join(repl)
|
|
92
|
+
os[i] = otemp.split(otemp.substr(oi, ofjl)).join(repl)
|
|
97
93
|
}
|
|
98
94
|
|
|
99
95
|
if (countObj) {
|
|
100
|
-
countObj.value += temp.split(f[j]).length - 1
|
|
96
|
+
countObj.value += temp.split(f[j]).length - 1
|
|
101
97
|
}
|
|
102
98
|
}
|
|
103
99
|
}
|
|
104
100
|
|
|
105
|
-
return osa ? os : os[0]
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=str_ireplace.js.map
|
|
101
|
+
return osa ? os : os[0]
|
|
102
|
+
}
|
package/php/strings/str_pad.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
module.exports = function str_pad(input, padLength, padString, padType) {
|
|
4
2
|
// discuss at: https://locutus.io/php/str_pad/
|
|
5
3
|
// original by: Kevin van Zonneveld (https://kvz.io)
|
|
@@ -11,38 +9,37 @@ module.exports = function str_pad(input, padLength, padString, padType) {
|
|
|
11
9
|
// example 2: str_pad('Kevin van Zonneveld', 30, '-', 'STR_PAD_BOTH')
|
|
12
10
|
// returns 2: '------Kevin van Zonneveld-----'
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
let half = ''
|
|
13
|
+
let padToGo
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const _strPadRepeater = function (s, len) {
|
|
16
|
+
let collect = ''
|
|
19
17
|
|
|
20
18
|
while (collect.length < len) {
|
|
21
|
-
collect += s
|
|
19
|
+
collect += s
|
|
22
20
|
}
|
|
23
|
-
collect = collect.substr(0, len)
|
|
21
|
+
collect = collect.substr(0, len)
|
|
24
22
|
|
|
25
|
-
return collect
|
|
26
|
-
}
|
|
23
|
+
return collect
|
|
24
|
+
}
|
|
27
25
|
|
|
28
|
-
input += ''
|
|
29
|
-
padString = padString !== undefined ? padString : ' '
|
|
26
|
+
input += ''
|
|
27
|
+
padString = padString !== undefined ? padString : ' '
|
|
30
28
|
|
|
31
29
|
if (padType !== 'STR_PAD_LEFT' && padType !== 'STR_PAD_RIGHT' && padType !== 'STR_PAD_BOTH') {
|
|
32
|
-
padType = 'STR_PAD_RIGHT'
|
|
30
|
+
padType = 'STR_PAD_RIGHT'
|
|
33
31
|
}
|
|
34
32
|
if ((padToGo = padLength - input.length) > 0) {
|
|
35
33
|
if (padType === 'STR_PAD_LEFT') {
|
|
36
|
-
input = _strPadRepeater(padString, padToGo) + input
|
|
34
|
+
input = _strPadRepeater(padString, padToGo) + input
|
|
37
35
|
} else if (padType === 'STR_PAD_RIGHT') {
|
|
38
|
-
input = input + _strPadRepeater(padString, padToGo)
|
|
36
|
+
input = input + _strPadRepeater(padString, padToGo)
|
|
39
37
|
} else if (padType === 'STR_PAD_BOTH') {
|
|
40
|
-
half = _strPadRepeater(padString, Math.ceil(padToGo / 2))
|
|
41
|
-
input = half + input + half
|
|
42
|
-
input = input.substr(0, padLength)
|
|
38
|
+
half = _strPadRepeater(padString, Math.ceil(padToGo / 2))
|
|
39
|
+
input = half + input + half
|
|
40
|
+
input = input.substr(0, padLength)
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
return input
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=str_pad.js.map
|
|
44
|
+
return input
|
|
45
|
+
}
|