Skip to content

Commit

Permalink
fix: formdata used in cjs (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
troyeagle authored Sep 21, 2023
1 parent 9b28f96 commit 80afc30
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Alipay SDK for Node.js 用于给 Node 服务器提供调用支付宝开放平台
### 普通公钥模式
```typescript
const AlipaySdk = require('alipay-sdk');
// TypeScript,可以使用 import AlipaySdk from 'alipay-sdk';
// esmodule / typescript,可以使用 import AlipaySdk from 'alipay-sdk';
// 普通公钥模式
const alipaySdk = new AlipaySdk({
appId: '2016123456789012',
Expand Down Expand Up @@ -103,7 +103,7 @@ const result = await alipay.exec('alipay.trade.pay', {
### 使用 AlipayFormData 配置表单
部分接口需要上传文件。SDK 内部封装了一个 Form 对象,用以在发起 multipart/form-data 请求时使用。以 [上传门店照片和视频接口](https://opendocs.alipay.com/apis/api_3/alipay.offline.material.image.upload) 为例:
```typescript
import AlipayFormData from 'alipay-sdk/lib/form';
const AlipayFormData = require('alipay-sdk/lib/form');

const formData = new AlipayFormData();

Expand Down
3 changes: 3 additions & 0 deletions lib/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ class AliPayForm {
}
}

exports = module.exports = AliPayForm;
Object.defineProperty(exports, '__esModule', { value: true });

export default AliPayForm;
10 changes: 10 additions & 0 deletions test/require.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ describe('require', () => {
});
assert.equal(typeof sdk.exec, 'function');
});

it('should require work on normal cjs for AlipayFormData', () => {
const AlipayForm = require('../lib/form');
const AlipayForm2 = require('../lib/form').default;
assert.strictEqual(AlipayForm, AlipayForm2);

const form = new AlipayForm();

assert.equal(typeof form.addFile, 'function');
})
});

0 comments on commit 80afc30

Please sign in to comment.