Skip to content

Upgrade #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 136 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"release": "semantic-release"
},
"devDependencies": {
"@fink/cli": "^6.0.0",
"@fink/jest": "^5.0.0",
"@fink/cli": "^6.1.0",
"@fink/jest": "^5.1.0",
"@fink/larix": "^12.0.0",
"@fink/loxia": "^12.0.0",
"@fink/loxia": "^12.0.2",
"commitizen": "^4.0.5",
"cz-conventional-changelog": "^3.1.0",
"jest-cli": "^26.1.0",
Expand All @@ -44,6 +44,6 @@
}
},
"dependencies": {
"@fink/js-interop": "^1.0.0"
"@fink/js-interop": "^1.1.0"
}
}
1 change: 1 addition & 0 deletions src/iter.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{max_int} = import './num'
{new} = import '@fink/js-interop/reflect'
{Symbol, Set} = import '@fink/js-interop/globals'

# TODO add:
# partition
Expand Down
2 changes: 2 additions & 0 deletions src/json.fnk
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{JSON} = import '@fink/js-interop/globals'

json_to_obj = JSON.parse

obj_to_json = JSON.stringify
1 change: 1 addition & 0 deletions src/math.fnk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

{Math} = import '@fink/js-interop/globals'


Pi = Math.PI
Expand Down
1 change: 1 addition & 0 deletions src/math.test.fnk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{describe, it, expect, to_equal} = import '@fink/jest'
{Math} = import '@fink/js-interop/globals'

{π, clamp} = import './math'

Expand Down
11 changes: 11 additions & 0 deletions src/num.fnk
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{parseFloat, parseInt, Number, isNaN, isFinite} = import '@fink/js-interop/globals'
{is_instance, get_type} = import '@fink/js-interop/reflect'


# TODO: should that live in str?
parse_float = fn str: parseFloat str

Expand All @@ -19,3 +23,10 @@ is_not_a_num = isNaN
is_finite = isFinite

base_n = fn num, radix: num.toString radix


is_num = fn num:
match num:
'number' == get_type ?: true
is_instance ?, Number: true
else: false
21 changes: 20 additions & 1 deletion src/num.test.fnk
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{describe, it, expect, to_equal} = import '@fink/jest'
{new} = import '@fink/js-interop/reflect'
{Number} = import '@fink/js-interop/globals'

{parse_int, parse_float, base_n} = import './num'
{parse_int, parse_float, base_n, is_num} = import './num'


describe 'numbers', fn:
Expand Down Expand Up @@ -38,3 +40,20 @@ describe 'numbers', fn:
base_n 1234, 36
to_equal
'ya'



describe 'is_num', fn:
it 'is a number', fn:
expect
is_num 1234
to_equal true

expect
is_num new Number, 1234
to_equal true

it 'is not a number', fn:
expect
is_num '1234'
to_equal false
2 changes: 2 additions & 0 deletions src/obj.fnk
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{Object} = import '@fink/js-interop/globals'


obj_keys = Object.keys

Expand Down
3 changes: 2 additions & 1 deletion src/regex.fnk
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{new} = import '@fink/js-interop/reflect'
{RegExp} = import '@fink/js-interop/globals'

{raw} = import './str'


regex = fn pattern, flags='':
# TODO: should @fink/js-interop provide the regexp function?
new RegExp, pattern, 'u${flags}'


Expand Down
2 changes: 2 additions & 0 deletions src/stack-trace.fnk
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{Error} = import '@fink/js-interop/globals'


stack_trace = fn func=stack_trace:
err = {}
Expand Down
12 changes: 11 additions & 1 deletion src/str.fnk
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{new} = import '@fink/js-interop/reflect'
{is_instance, get_type} = import '@fink/js-interop/reflect'
{String, TextEncoder, TextDecoder} = import '@fink/js-interop/globals'


from_char_codes = String.fromCharCode
Expand All @@ -25,6 +27,7 @@ trim = fn str: str.trim _
trim_start = fn str: str.trimStart _
trim_end = fn str: str.trimEnd _


# TODO should this be handled by '...' * 3 in loxia?
repeat = fn str, num: str.repeat num

Expand All @@ -41,4 +44,11 @@ encode = fn text, encoding:

decode = fn bytes, encoding:
encoder = new TextDecoder, encoding
encoder.decode bytes
encoder.decode bytes


is_str = fn str:
match str:
'string' == get_type ?: true
is_instance ?, String: true
else: false
25 changes: 22 additions & 3 deletions src/str.test.fnk
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
{describe, it, expect, to_equal} = import '@fink/jest'
{new} = import '@fink/js-interop/reflect'
{Uint8Array, String} = import '@fink/js-interop/globals'


{
from_char_codes, from_code_points, char_code, code_point

ends_with, starts_with

matches, match_all, find_index, split, replace

slice

pad_start, pad_end, trim, trim_start, trim_end

repeat, lower_case, upper_case

raw, rx
raw

encode, decode

is_str
} = import './str'


Expand Down Expand Up @@ -130,3 +133,19 @@ describe 'codecs', fn:
to_equal 'foobar'



describe 'is_str', fn:
it 'is a string', fn:
expect
is_str 'foobar'
to_equal true

expect
is_str new String, 1234
to_equal true

it 'is not a string', fn:
expect
is_str 1234
to_equal false