@arms/rum-core 0.0.25-beta.13 → 0.0.25-beta.15
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/es/index.d.ts +17 -0
- package/es/index.js +17 -0
- package/es/model/client.d.ts +20 -0
- package/es/model/client.js +73 -0
- package/es/model/context.d.ts +18 -0
- package/es/model/context.js +38 -0
- package/es/model/reporter.d.ts +30 -0
- package/es/model/reporter.js +131 -0
- package/es/model/shell.d.ts +33 -0
- package/es/model/shell.js +80 -0
- package/es/style.js +1 -0
- package/es/types/client.d.ts +133 -0
- package/es/types/client.js +4 -0
- package/es/types/collector.d.ts +7 -0
- package/es/types/collector.js +1 -0
- package/es/types/processor.d.ts +8 -0
- package/es/types/processor.js +1 -0
- package/es/types/reporter.d.ts +8 -0
- package/es/types/reporter.js +1 -0
- package/es/types/rum-event.d.ts +163 -0
- package/es/types/rum-event.js +24 -0
- package/es/types/shell.d.ts +28 -0
- package/es/types/shell.js +1 -0
- package/es/utils/base.d.ts +39 -0
- package/es/utils/base.js +131 -0
- package/es/utils/exception.d.ts +7 -0
- package/es/utils/exception.js +10 -0
- package/es/utils/is.d.ts +12 -0
- package/es/utils/is.js +33 -0
- package/es/utils/match.d.ts +7 -0
- package/es/utils/match.js +37 -0
- package/es/utils/number.d.ts +17 -0
- package/es/utils/number.js +40 -0
- package/es/utils/polyfills.d.ts +7 -0
- package/es/utils/polyfills.js +28 -0
- package/es/utils/trace.d.ts +28 -0
- package/es/utils/trace.js +101 -0
- package/lib/model/client.d.ts +2 -2
- package/lib/model/client.js +6 -2
- package/lib/model/context.d.ts +3 -2
- package/lib/model/context.js +6 -1
- package/lib/model/reporter.js +3 -1
- package/lib/types/client.d.ts +21 -1
- package/lib/types/processor.d.ts +1 -0
- package/lib/types/rum-event.d.ts +11 -2
- package/lib/types/rum-event.js +11 -1
- package/lib/utils/base.d.ts +1 -3
- package/lib/utils/base.js +2 -10
- package/lib/utils/number.d.ts +4 -1
- package/lib/utils/number.js +6 -4
- package/package.json +4 -3
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { isMatchOption } from "./match";
|
|
2
|
+
import { isArray, isBoolean, isNumber } from "./is";
|
|
3
|
+
import { encode } from "js-base64";
|
|
4
|
+
export function isTraceOption(option) {
|
|
5
|
+
return option && isMatchOption(option.match) && isArray(option.propagatorTypes);
|
|
6
|
+
}
|
|
7
|
+
export function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, subOption) {
|
|
8
|
+
if (subOption === void 0) {
|
|
9
|
+
subOption = {};
|
|
10
|
+
}
|
|
11
|
+
var tracingHeaders = {};
|
|
12
|
+
var sample = sampled ? '1' : '0';
|
|
13
|
+
// skywalking 标准具备排他性,如果包含sw8,则只使用sw8
|
|
14
|
+
if (propagatorTypes.includes('sw8')) {
|
|
15
|
+
propagatorTypes = ['sw8'];
|
|
16
|
+
}
|
|
17
|
+
propagatorTypes.forEach(function (propagatorType) {
|
|
18
|
+
switch (propagatorType) {
|
|
19
|
+
case 'jaeger':
|
|
20
|
+
tracingHeaders['uber-trace-id'] = traceId + ":" + spanId + ":0:" + sample;
|
|
21
|
+
break;
|
|
22
|
+
case 'b3':
|
|
23
|
+
// https://github.com/openzipkin/b3-propagation
|
|
24
|
+
tracingHeaders['b3'] = traceId + "-" + spanId + "-" + sample;
|
|
25
|
+
break;
|
|
26
|
+
case 'b3multi':
|
|
27
|
+
tracingHeaders['X-B3-TraceId'] = traceId;
|
|
28
|
+
tracingHeaders['X-B3-SpanId'] = spanId;
|
|
29
|
+
tracingHeaders['X-B3-Sampled'] = sample;
|
|
30
|
+
break;
|
|
31
|
+
case 'sw8':
|
|
32
|
+
// https://github.com/apache/skywalking-client-js
|
|
33
|
+
var traceIdStr = String(encode(traceId));
|
|
34
|
+
var segmentId = String(encode(spanId));
|
|
35
|
+
var service = String(encode(subOption.appId));
|
|
36
|
+
var instance = String(encode(subOption.appVersion));
|
|
37
|
+
var endpoint = String(encode(subOption.viewName));
|
|
38
|
+
var peer = String(encode(subOption.host));
|
|
39
|
+
tracingHeaders['sw8'] = sample + "-" + traceIdStr + "-" + segmentId + "-" + 0 + "-" + service + "-" + instance + "-" + endpoint + "-" + peer;
|
|
40
|
+
break;
|
|
41
|
+
case 'tracecontext':
|
|
42
|
+
default:
|
|
43
|
+
// https://www.w3.org/TR/trace-context/
|
|
44
|
+
tracingHeaders['traceparent'] = "00-" + traceId + "-" + spanId + "-0" + sample;
|
|
45
|
+
if (subOption.tracestate) {
|
|
46
|
+
tracingHeaders['tracestate'] = subOption.tracestate;
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
if (subOption.baggage) {
|
|
52
|
+
tracingHeaders['baggage'] = subOption.baggage;
|
|
53
|
+
}
|
|
54
|
+
return tracingHeaders;
|
|
55
|
+
}
|
|
56
|
+
export function parseTracingOptions(tracingOption) {
|
|
57
|
+
var defPropagatorTypes = ['tracecontext'];
|
|
58
|
+
if (isBoolean(tracingOption) || !tracingOption) {
|
|
59
|
+
return {
|
|
60
|
+
enable: !!tracingOption,
|
|
61
|
+
sample: 100,
|
|
62
|
+
propagatorTypes: defPropagatorTypes,
|
|
63
|
+
allowedUrls: [],
|
|
64
|
+
tracestate: true,
|
|
65
|
+
baggage: false
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
var _tracingOption$enable = tracingOption.enable,
|
|
69
|
+
enable = _tracingOption$enable === void 0 ? true : _tracingOption$enable,
|
|
70
|
+
_tracingOption$sample = tracingOption.sample,
|
|
71
|
+
sample = _tracingOption$sample === void 0 ? 100 : _tracingOption$sample,
|
|
72
|
+
_tracingOption$propag = tracingOption.propagatorTypes,
|
|
73
|
+
propagatorTypes = _tracingOption$propag === void 0 ? defPropagatorTypes : _tracingOption$propag,
|
|
74
|
+
_tracingOption$allowe = tracingOption.allowedUrls,
|
|
75
|
+
allowedUrls = _tracingOption$allowe === void 0 ? [] : _tracingOption$allowe,
|
|
76
|
+
_tracingOption$traces = tracingOption.tracestate,
|
|
77
|
+
tracestate = _tracingOption$traces === void 0 ? true : _tracingOption$traces,
|
|
78
|
+
_tracingOption$baggag = tracingOption.baggage,
|
|
79
|
+
baggage = _tracingOption$baggag === void 0 ? false : _tracingOption$baggag;
|
|
80
|
+
var traceOptions = [];
|
|
81
|
+
if (isArray(allowedUrls) && allowedUrls.length) {
|
|
82
|
+
allowedUrls.forEach(function (item) {
|
|
83
|
+
if (isMatchOption(item)) {
|
|
84
|
+
traceOptions.push({
|
|
85
|
+
match: item,
|
|
86
|
+
propagatorTypes: propagatorTypes
|
|
87
|
+
});
|
|
88
|
+
} else if (isTraceOption(item)) {
|
|
89
|
+
traceOptions.push(item);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
enable: isBoolean(enable) ? enable : true,
|
|
95
|
+
sample: isNumber(sample) ? sample : 100,
|
|
96
|
+
propagatorTypes: propagatorTypes,
|
|
97
|
+
allowedUrls: traceOptions,
|
|
98
|
+
tracestate: tracestate,
|
|
99
|
+
baggage: baggage
|
|
100
|
+
};
|
|
101
|
+
}
|
package/lib/model/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IClient, IConfiguration, IContext } from '../types/client';
|
|
1
|
+
import { IClient, IConfiguration, IContext, IRumSession } from '../types/client';
|
|
2
2
|
import { RumEvent } from '../types/rum-event';
|
|
3
3
|
import { IProcessor } from '../types/processor';
|
|
4
4
|
import { ICollector } from '../types/collector';
|
|
@@ -9,7 +9,7 @@ declare class Client implements IClient {
|
|
|
9
9
|
private processors;
|
|
10
10
|
private reporter;
|
|
11
11
|
private ctx;
|
|
12
|
-
init(config: IConfiguration): void;
|
|
12
|
+
init(config: IConfiguration, rumSession?: IRumSession): void;
|
|
13
13
|
sendEvent: (payload: RumEvent) => void;
|
|
14
14
|
setContext(ctx: IContext): void;
|
|
15
15
|
getContext(): IContext;
|
package/lib/model/client.js
CHANGED
|
@@ -6,6 +6,7 @@ exports["default"] = void 0;
|
|
|
6
6
|
var _client = require("../types/client");
|
|
7
7
|
var _events = require("events");
|
|
8
8
|
var _context = _interopRequireDefault(require("./context"));
|
|
9
|
+
var _is = require("../utils/is");
|
|
9
10
|
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
11
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
12
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
@@ -22,13 +23,16 @@ var Client = /*#__PURE__*/function () {
|
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
var _proto = Client.prototype;
|
|
25
|
-
_proto.init = function init(config) {
|
|
26
|
+
_proto.init = function init(config, rumSession) {
|
|
26
27
|
var _this2 = this;
|
|
27
|
-
this.ctx = new _context["default"](config);
|
|
28
|
+
this.ctx = new _context["default"](config, rumSession);
|
|
28
29
|
var ctx = this.ctx,
|
|
29
30
|
collectors = this.collectors,
|
|
30
31
|
processors = this.processors,
|
|
31
32
|
reporter = this.reporter;
|
|
33
|
+
processors.forEach(function (processor) {
|
|
34
|
+
(0, _is.isFunction)(processor.setup) && processor.setup(ctx);
|
|
35
|
+
});
|
|
32
36
|
|
|
33
37
|
// collector 收集数据统一 push 到各匹配 processor
|
|
34
38
|
this.emitter.on(_client.EventType.collect, function (payload) {
|
package/lib/model/context.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { IConfiguration, IContext } from "../types/client";
|
|
1
|
+
import { IConfiguration, IContext, IRumSession } from "../types/client";
|
|
2
2
|
import { RumEvent, IViewData } from "../types/rum-event";
|
|
3
3
|
declare class Context implements IContext {
|
|
4
4
|
private config;
|
|
5
5
|
private rumEvent;
|
|
6
6
|
private views;
|
|
7
|
-
|
|
7
|
+
session: IRumSession;
|
|
8
|
+
constructor(config: IConfiguration, rumSession?: IRumSession);
|
|
8
9
|
getConfig(): IConfiguration;
|
|
9
10
|
setConfig(config: IConfiguration): void;
|
|
10
11
|
getViews(): IViewData[];
|
package/lib/model/context.js
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports["default"] = void 0;
|
|
5
5
|
var Context = /*#__PURE__*/function () {
|
|
6
|
-
function Context(config) {
|
|
6
|
+
function Context(config, rumSession) {
|
|
7
7
|
this.config = config;
|
|
8
8
|
this.rumEvent = void 0;
|
|
9
9
|
this.views = [];
|
|
10
|
+
this.session = void 0;
|
|
11
|
+
if (rumSession) {
|
|
12
|
+
this.session = rumSession;
|
|
13
|
+
this.session.init(config);
|
|
14
|
+
}
|
|
10
15
|
}
|
|
11
16
|
var _proto = Context.prototype;
|
|
12
17
|
_proto.getConfig = function getConfig() {
|
package/lib/model/reporter.js
CHANGED
|
@@ -117,7 +117,9 @@ var Reporter = exports["default"] = /*#__PURE__*/function () {
|
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
|
-
|
|
120
|
+
var session = ctx.session;
|
|
121
|
+
var sampled = session ? session.getSampled() : true;
|
|
122
|
+
sampled && this.request(ctx, eventQueue, curView);
|
|
121
123
|
this.eventQueue = [];
|
|
122
124
|
}
|
|
123
125
|
|
package/lib/types/client.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare enum EventType {
|
|
|
10
10
|
collect = "collect"
|
|
11
11
|
}
|
|
12
12
|
export interface IContext {
|
|
13
|
+
session: IRumSession;
|
|
13
14
|
/**
|
|
14
15
|
* user config
|
|
15
16
|
*/
|
|
@@ -28,11 +29,26 @@ export interface IContext {
|
|
|
28
29
|
setRumEvent(rumEvent: RumEvent): void;
|
|
29
30
|
[key: string]: any;
|
|
30
31
|
}
|
|
32
|
+
export interface SessionConfig {
|
|
33
|
+
sampleRate?: number;
|
|
34
|
+
maxDuration?: number;
|
|
35
|
+
overtime?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface IRumSession {
|
|
38
|
+
init(config: IConfiguration): void;
|
|
39
|
+
sessionConfig: SessionConfig;
|
|
40
|
+
getSessionId: () => string;
|
|
41
|
+
getSampled: () => boolean;
|
|
42
|
+
updateSession: () => void;
|
|
43
|
+
getEventId: () => string;
|
|
44
|
+
getViewId: () => string;
|
|
45
|
+
getUserId: () => string;
|
|
46
|
+
}
|
|
31
47
|
export interface IClient {
|
|
32
48
|
/**
|
|
33
49
|
* 初始化
|
|
34
50
|
*/
|
|
35
|
-
init: (configuration: IConfiguration) => void;
|
|
51
|
+
init: (configuration: IConfiguration, rumSession?: IRumSession) => void;
|
|
36
52
|
/**
|
|
37
53
|
* 业务自定义上传数据
|
|
38
54
|
*/
|
|
@@ -95,6 +111,10 @@ export interface IConfiguration {
|
|
|
95
111
|
flushTime?: number;
|
|
96
112
|
maxEventCount?: number;
|
|
97
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* session config
|
|
116
|
+
*/
|
|
117
|
+
sessionConfig?: SessionConfig;
|
|
98
118
|
/**
|
|
99
119
|
* 各个 collector config
|
|
100
120
|
*/
|
package/lib/types/processor.d.ts
CHANGED
package/lib/types/rum-event.d.ts
CHANGED
|
@@ -42,13 +42,21 @@ export interface RumViewEvent extends RumBaseEvent {
|
|
|
42
42
|
url?: string;
|
|
43
43
|
timing_data?: string;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* 枚举值,表示资源是否加载成功
|
|
47
|
+
*/
|
|
48
|
+
export declare enum ResourceStatus {
|
|
49
|
+
Unknown = -1,
|
|
50
|
+
Failed = 0,
|
|
51
|
+
Success = 1
|
|
52
|
+
}
|
|
45
53
|
export interface RumResourceEvent extends RumBaseEvent {
|
|
46
54
|
name?: string;
|
|
47
55
|
type?: string;
|
|
48
56
|
method?: string;
|
|
49
57
|
status_code?: number | string;
|
|
50
58
|
message?: string;
|
|
51
|
-
success?: -1 | 0 | 1;
|
|
59
|
+
success?: -1 | 0 | 1 | ResourceStatus;
|
|
52
60
|
trace_id?: string;
|
|
53
61
|
duration?: number;
|
|
54
62
|
size?: number;
|
|
@@ -96,7 +104,8 @@ export interface RumCustomEvent extends RumBaseEvent {
|
|
|
96
104
|
export type RumEvent = RumViewEvent | RumResourceEvent | RumExceptionEvent | RumActionEvent | RumCustomEvent;
|
|
97
105
|
export declare enum AppType {
|
|
98
106
|
browser = "browser",
|
|
99
|
-
miniapp = "miniapp"
|
|
107
|
+
miniapp = "miniapp",
|
|
108
|
+
uniapp = "uniapp"
|
|
100
109
|
}
|
|
101
110
|
export interface RumEventBundle {
|
|
102
111
|
app: {
|
package/lib/types/rum-event.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.RumEventType = exports.AppType = void 0;
|
|
4
|
+
exports.RumEventType = exports.ResourceStatus = exports.AppType = void 0;
|
|
5
5
|
var RumEventType = exports.RumEventType = /*#__PURE__*/function (RumEventType) {
|
|
6
6
|
RumEventType["VIEW"] = "view";
|
|
7
7
|
RumEventType["RESOURCE"] = "resource";
|
|
@@ -11,8 +11,18 @@ var RumEventType = exports.RumEventType = /*#__PURE__*/function (RumEventType) {
|
|
|
11
11
|
RumEventType["CUSTOM"] = "custom";
|
|
12
12
|
return RumEventType;
|
|
13
13
|
}({});
|
|
14
|
+
/**
|
|
15
|
+
* 枚举值,表示资源是否加载成功
|
|
16
|
+
*/
|
|
17
|
+
var ResourceStatus = exports.ResourceStatus = /*#__PURE__*/function (ResourceStatus) {
|
|
18
|
+
ResourceStatus[ResourceStatus["Unknown"] = -1] = "Unknown";
|
|
19
|
+
ResourceStatus[ResourceStatus["Failed"] = 0] = "Failed";
|
|
20
|
+
ResourceStatus[ResourceStatus["Success"] = 1] = "Success";
|
|
21
|
+
return ResourceStatus;
|
|
22
|
+
}({});
|
|
14
23
|
var AppType = exports.AppType = /*#__PURE__*/function (AppType) {
|
|
15
24
|
AppType["browser"] = "browser";
|
|
16
25
|
AppType["miniapp"] = "miniapp";
|
|
26
|
+
AppType["uniapp"] = "uniapp";
|
|
17
27
|
return AppType;
|
|
18
28
|
}({});
|
package/lib/utils/base.d.ts
CHANGED
|
@@ -22,11 +22,9 @@ export declare function generateSpanId(len?: number, radix?: number): string;
|
|
|
22
22
|
/**
|
|
23
23
|
* @description: 随机生成 eventId
|
|
24
24
|
* @param sessionId {string} sessionId
|
|
25
|
-
* @param sampled {boolean} 是否命中采样
|
|
26
|
-
* @param samplingType {string} 采样类型
|
|
27
25
|
* @return {String}
|
|
28
26
|
*/
|
|
29
|
-
export declare function generateEventId(sessionId: string
|
|
27
|
+
export declare function generateEventId(sessionId: string): string;
|
|
30
28
|
/**
|
|
31
29
|
* @desc 函数防抖
|
|
32
30
|
* @param func 回调函数
|
package/lib/utils/base.js
CHANGED
|
@@ -95,19 +95,11 @@ function generateSpanId(len, radix) {
|
|
|
95
95
|
/**
|
|
96
96
|
* @description: 随机生成 eventId
|
|
97
97
|
* @param sessionId {string} sessionId
|
|
98
|
-
* @param sampled {boolean} 是否命中采样
|
|
99
|
-
* @param samplingType {string} 采样类型
|
|
100
98
|
* @return {String}
|
|
101
99
|
*/
|
|
102
|
-
function generateEventId(sessionId
|
|
103
|
-
if (sampled === void 0) {
|
|
104
|
-
sampled = true;
|
|
105
|
-
}
|
|
106
|
-
if (samplingType === void 0) {
|
|
107
|
-
samplingType = '0';
|
|
108
|
-
}
|
|
100
|
+
function generateEventId(sessionId) {
|
|
109
101
|
var spanId = generateSpanId();
|
|
110
|
-
return "00-" + sessionId + "-" + spanId
|
|
102
|
+
return "00-" + sessionId + "-" + spanId;
|
|
111
103
|
}
|
|
112
104
|
|
|
113
105
|
/**
|
package/lib/utils/number.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
export declare const ONE_SECOND = 1000;
|
|
2
|
+
export declare const ONE_MINUTE: number;
|
|
3
|
+
export declare const ONE_HOUR: number;
|
|
4
|
+
export declare const ONE_DAY: number;
|
|
1
5
|
/**
|
|
2
6
|
* Return true if the draw is successful
|
|
3
7
|
* @param threshold between 0 and 100
|
|
4
8
|
*/
|
|
5
9
|
export declare function performDraw(threshold: number): boolean;
|
|
6
|
-
export declare function round(num: number, decimals: 0 | 1 | 2 | 3 | 4): number;
|
|
7
10
|
/**
|
|
8
11
|
* 保留指定位数的小数
|
|
9
12
|
* @param num 原数据
|
package/lib/utils/number.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
+
exports.ONE_SECOND = exports.ONE_MINUTE = exports.ONE_HOUR = exports.ONE_DAY = void 0;
|
|
4
5
|
exports.formatNumber = formatNumber;
|
|
5
6
|
exports.performDraw = performDraw;
|
|
6
|
-
exports.
|
|
7
|
+
var ONE_SECOND = exports.ONE_SECOND = 1e3;
|
|
8
|
+
var ONE_MINUTE = exports.ONE_MINUTE = 60 * ONE_SECOND;
|
|
9
|
+
var ONE_HOUR = exports.ONE_HOUR = 60 * ONE_MINUTE;
|
|
10
|
+
var ONE_DAY = exports.ONE_DAY = 24 * ONE_HOUR;
|
|
11
|
+
|
|
7
12
|
/**
|
|
8
13
|
* Return true if the draw is successful
|
|
9
14
|
* @param threshold between 0 and 100
|
|
@@ -11,9 +16,6 @@ exports.round = round;
|
|
|
11
16
|
function performDraw(threshold) {
|
|
12
17
|
return threshold !== 0 && Math.random() * 100 <= threshold;
|
|
13
18
|
}
|
|
14
|
-
function round(num, decimals) {
|
|
15
|
-
return +num.toFixed(decimals);
|
|
16
|
-
}
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* 保留指定位数的小数
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arms/rum-core",
|
|
3
|
-
"version": "0.0.25-beta.
|
|
3
|
+
"version": "0.0.25-beta.15",
|
|
4
4
|
"description": "arms rum javascript sdk core",
|
|
5
5
|
"author": "guangli.fj <guangli.fj@alibaba-inc.com>",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
|
+
"module": "es/index.js",
|
|
8
9
|
"directories": {
|
|
9
10
|
"lib": "lib",
|
|
10
11
|
"test": "__tests__"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
|
-
"lib"
|
|
14
|
+
"lib",
|
|
15
|
+
"es"
|
|
14
16
|
],
|
|
15
17
|
"publishConfig": {
|
|
16
18
|
"access": "public"
|
|
@@ -18,7 +20,6 @@
|
|
|
18
20
|
"scripts": {
|
|
19
21
|
"start": "build-scripts build --watch",
|
|
20
22
|
"build": "build-scripts build --skip-demo",
|
|
21
|
-
"prepublishOnly": "npm run build",
|
|
22
23
|
"test": "node ./__tests__/@arms/core.test.js"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|