Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

teambition-server-sdk

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

teambition-server-sdk - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

.gitmessage.text

28

lib/datafactory.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* 数据工厂,对数据进行加工、处理
* @class DataFactory
*/
class DataFactory {

@@ -7,2 +11,9 @@ constructor(raw) {

}
/**
* 数据分片请求获取
* @param {function} job
* @param {number} [capacity=200]
* @returns {Promise<any>}
* @memberof DataFactory
*/
async JobSlice(job, capacity = 200) {

@@ -12,2 +23,5 @@ if (!Array.isArray(this.raw)) {

}
if (typeof job !== 'function') {
throw new Error('job must be a func');
}
// 分片请求

@@ -17,6 +31,8 @@ const dataSize = this.raw.length;

let result;
let index = 0;
let start = 0;
let end = capacity;
// 保证顺序性
while (true) {
if (capacity >= dataSize) {
result = await job(this.raw.slice(index));
if (end >= dataSize) {
result = await job(this.raw.slice(start));
ret = ret.concat(result);

@@ -26,6 +42,6 @@ break;

else {
result = await job(this.raw.slice(index, capacity));
result = await job(this.raw.slice(start, end));
ret = ret.concat(result);
index = capacity;
capacity += capacity;
start = end;
end = capacity + end;
}

@@ -32,0 +48,0 @@ }

@@ -5,1 +5,3 @@ "use strict";

exports.DataFactory = datafactory_1.DataFactory;
const interface_1 = require("./interface");
exports.Client = interface_1.default;
{
"name": "teambition-server-sdk",
"version": "0.0.2",
"version": "0.0.3",
"description": "Javascript SDK for teambition server",

@@ -22,2 +22,3 @@ "main": "lib/index.js",

"@types/mocha": "^5.2.5",
"@types/request-promise": "^4.1.42",
"mocha": "^5.2.0",

@@ -28,3 +29,6 @@ "should": "^13.2.3",

"typescript": "^3.1.3"
},
"dependencies": {
"request-promise": "^4.2.2"
}
}
## Teambition Server SDK
Teambition 服务端 Node SDK,封装如下方法:
- [ ] 数据处理: 常用的数据加工处理方法
- [ ] 官方 API: 常用的 `Teambition` 主站官方 API 封装,使用者不应该关注具体 URL 的变动
- [ ] 工具函数: 封装与 `Teambition` 强相关的业务需要使用到的工具函数
### 数据处理
**JobSlice(分片执行)**
```js
// JS Demo
function request (sliceRaw) {
// do anything
}
const raw = new Array(20)
const datafactory = new TeambitionSDK.DataFactory(raw)
datafactory.JobSlice(request)
```
### 官方 API
import { DataFactory } from './datafactory'
import Client from './interface'
export {
DataFactory,
Client
}

@@ -12,5 +12,4 @@ {

"include": [
"src/**/*",
"test/**/*"
"src/**/*"
]
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc