Skip to content
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

Support to ECMAScript modules with mjs file extension #21

Merged
merged 12 commits into from
Mar 11, 2024
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
13 changes: 8 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Build
on:
on:
workflow_dispatch:
workflow_call:
pull_request:
Expand All @@ -10,7 +10,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.20.x]
go-version: [1.22.x]
os: [ubuntu-latest]
targetplatform: [x64]

Expand All @@ -26,9 +26,10 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache: false

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Get dependencies
working-directory: ./cmd
Expand All @@ -41,7 +42,9 @@ jobs:
GOOS=js GOARCH=wasm GO111MODULE=on go test -exec="$(go env GOROOT)/misc/wasm/go_js_wasm_exec" -v ./... -coverprofile=coverage.txt -covermode=atomic

- name: Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
directory: ./cmd
file: coverage.txt
Expand All @@ -65,5 +68,5 @@ jobs:
node ./node_modules/.bin/rollup -c
cp LICENSE ./dist
cp README.md ./dist
cp src/package.json ./dist
cp package.json ./dist
cp src/index.d.ts ./dist
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
node ./node_modules/.bin/rollup -c
cp LICENSE ./dist
cp README.md ./dist
cp src/package.json ./dist
cp package.json ./dist
cp src/index.d.ts ./dist

- name: NPM Publish
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package-lock.json
.DS_Store
Makefile
# Dependency directories
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Opera Mobile | ≥64
Samsung Internet | ≥7.2
UC Browser for Android | ≥13.4
QQ Browser | ≥10.4
Node.js | ≥8.0.0
Node.js | ≥12.0.0
Deno | ≥1.0

## Basic Usage
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Opera Mobile | ≥64
Samsung Internet | ≥7.2
UC Browser for Android | ≥13.4
QQ Browser | ≥10.4
Node.js | ≥8.0.0
Node.js | ≥12.0.0
Deno | ≥1.0

## 快速上手
Expand Down
8 changes: 4 additions & 4 deletions cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.18

require (
github.com/stretchr/testify v1.8.4
github.com/xuri/excelize/v2 v2.8.1-0.20231230064116-f4e395137d8f
golang.org/x/image v0.14.0
github.com/xuri/excelize/v2 v2.8.1
golang.org/x/image v0.15.0
)

require (
Expand All @@ -16,8 +16,8 @@ require (
github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/crypto v0.20.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 8 additions & 8 deletions cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 h1:Chd9DkqERQQuHpXjR/HSV1jLZA6uaoiwwH3vSuF3IW0=
github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.8.1-0.20231230064116-f4e395137d8f h1:5F5LQcT7GNZun38XY4MEQGPAzxzThpE9K+0INQX5lbE=
github.com/xuri/excelize/v2 v2.8.1-0.20231230064116-f4e395137d8f/go.mod h1:+tW2YujrsdTpYQHpxjYzBDpEQweZpdUeuAbevJhGMzg=
github.com/xuri/excelize/v2 v2.8.1 h1:pZLMEwK8ep+CLIUWpWmvW8IWE/yxqG0I1xcN6cVMGuQ=
github.com/xuri/excelize/v2 v2.8.1/go.mod h1:oli1E4C3Pa5RXg1TBXn4ENCXDV5JUMlBluUhG7c+CEE=
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 h1:qhbILQo1K3mphbwKh1vNm4oGezE1eF9fQWmNiIpSfI4=
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4=
golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg=
golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
24 changes: 24 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
"DuplicateRowTo": DuplicateRowTo(f),
"GetActiveSheetIndex": GetActiveSheetIndex(f),
"GetAppProps": GetAppProps(f),
"GetBaseColor": GetBaseColor(f),
"GetCellFormula": GetCellFormula(f),
"GetCellHyperLink": GetCellHyperLink(f),
"GetCellRichText": GetCellRichText(f),
Expand Down Expand Up @@ -1630,6 +1631,29 @@ func GetAppProps(f *excelize.File) func(this js.Value, args []js.Value) interfac
}
}

// GetBaseColor returns the preferred hex color code by giving hex color code,
// indexed color, and theme color.
func GetBaseColor(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
return func(this js.Value, args []js.Value) interface{} {
ret := map[string]interface{}{"color": "", "error": nil}
err := prepareArgs(args, []argsRule{
{types: []js.Type{js.TypeString}},
{types: []js.Type{js.TypeNumber}},
{types: []js.Type{js.TypeNumber}, opts: true},
})
if err != nil {
ret["error"] = err.Error()
return js.ValueOf(ret)
}
if len(args) == 3 {
themeColor := args[2].Int()
ret["color"] = f.GetBaseColor(args[0].String(), args[1].Int(), &themeColor)
}
ret["color"] = f.GetBaseColor(args[0].String(), args[1].Int(), nil)
return js.ValueOf(ret)
}
}

// GetCellFormula provides a function to get formula from cell by given
// worksheet name and cell reference in spreadsheet.
func GetCellFormula(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
Expand Down
19 changes: 19 additions & 0 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,25 @@ func TestGetActiveSheetIndex(t *testing.T) {
assert.Equal(t, 0, ret.Get("index").Int())
}

func TestGetBaseColor(t *testing.T) {
f := NewFile(js.Value{}, []js.Value{})
assert.True(t, f.(js.Value).Get("error").IsNull())

ret := f.(js.Value).Call("GetBaseColor", js.ValueOf("FFFFFF"), js.ValueOf(0))
assert.True(t, ret.Get("error").IsNull())
assert.Equal(t, "FFFFFF", ret.Get("color").String())

ret = f.(js.Value).Call("GetBaseColor", js.ValueOf("FFFFFF"), js.ValueOf(0), js.ValueOf(0))
assert.True(t, ret.Get("error").IsNull())
assert.Equal(t, "FFFFFF", ret.Get("color").String())

ret = f.(js.Value).Call("GetBaseColor")
assert.EqualError(t, errArgNum, ret.Get("error").String())

ret = f.(js.Value).Call("GetBaseColor", js.ValueOf("FFFFFF"), js.ValueOf(nil))
assert.Equal(t, errArgType.Error(), ret.Get("error").String())
}

func TestGetAppProps(t *testing.T) {
f := NewFile(js.Value{}, []js.Value{})
assert.True(t, f.(js.Value).Get("error").IsNull())
Expand Down
Loading
Loading