lyb-js 1.6.39 → 1.6.41
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/Math/LibJsPiecewiseLerp.d.ts +1 -1
- package/Math/LibJsPiecewiseLerp.js +3 -2
- package/README.md +4 -40
- package/package.json +1 -1
|
@@ -22,4 +22,4 @@ export interface LibJsPiecewiseLerpPoint {
|
|
|
22
22
|
* console.log(LibJsPiecewiseLerp(points, 9, 0)); // 65
|
|
23
23
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#libjspiecewiselerp-分段线性插值
|
|
24
24
|
*/
|
|
25
|
-
export declare const
|
|
25
|
+
export declare const libJsPiecewiseLerp: (points: LibJsPiecewiseLerpPoint[], currentValue: number, edgeValue: number) => number;
|
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
* console.log(LibJsPiecewiseLerp(points, 9, 0)); // 65
|
|
16
16
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#libjspiecewiselerp-分段线性插值
|
|
17
17
|
*/
|
|
18
|
-
export const
|
|
18
|
+
export const libJsPiecewiseLerp = (points, currentValue, edgeValue) => {
|
|
19
19
|
if (!points.length)
|
|
20
20
|
return edgeValue;
|
|
21
|
-
if (currentValue < points[0].h ||
|
|
21
|
+
if (currentValue < points[0].h ||
|
|
22
|
+
currentValue >= points[points.length - 1].h) {
|
|
22
23
|
return edgeValue;
|
|
23
24
|
}
|
|
24
25
|
for (let i = 0; i < points.length - 1; i++) {
|
package/README.md
CHANGED
|
@@ -26,53 +26,17 @@ yarn add lyb-js
|
|
|
26
26
|
|
|
27
27
|
## 起步
|
|
28
28
|
|
|
29
|
-
### 1.
|
|
29
|
+
### 1. 直接导入
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
当前默认已支持按需导入,不需要手动按分类路径引入或做聚合,直接从 `lyb-js` 引入即可。
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
const type = LibJs.Base.libJsGetDataType("Hello World");
|
|
37
|
-
console.log(type); // "string"
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### 2. 按需引入
|
|
41
|
-
|
|
42
|
-
更推荐。只引入当前用到的方法,路径按分类和文件名区分。
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
import { libJsGetDataType } from "lyb-js/Base/LibJsGetDataType";
|
|
46
|
-
import { libJsCalculateExpression } from "lyb-js/Math/LibJsCalculateExpression";
|
|
34
|
+
import { libJsGetDataType, libJsCalculateExpression } from "lyb-js";
|
|
47
35
|
|
|
48
36
|
console.log(libJsGetDataType([1, 2, 3])); // "array"
|
|
49
37
|
console.log(libJsCalculateExpression("(1+2)-(3*4)/5")); // 0.6
|
|
50
38
|
```
|
|
51
39
|
|
|
52
|
-
### 3. 项目内二次封装
|
|
53
|
-
|
|
54
|
-
如果同一批工具会在多个文件重复使用,建议在你自己的 `utils.ts` 中统一导出。
|
|
55
|
-
|
|
56
|
-
```ts
|
|
57
|
-
// utils.ts
|
|
58
|
-
export * from "lyb-js/Base/LibJsGetDataType";
|
|
59
|
-
export * from "lyb-js/Math/LibJsCalculateExpression";
|
|
60
|
-
export * from "lyb-js/Browser/LibJsGetRowValue";
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
// page.ts
|
|
65
|
-
import {
|
|
66
|
-
libJsGetDataType,
|
|
67
|
-
libJsCalculateExpression,
|
|
68
|
-
libJsGetRowValue,
|
|
69
|
-
} from "./utils";
|
|
70
|
-
|
|
71
|
-
console.log(libJsGetDataType({ a: 1 })); // "object"
|
|
72
|
-
console.log(libJsCalculateExpression("10/4", 2)); // 2.5
|
|
73
|
-
console.log(libJsGetRowValue({ user: { name: "Tom" } }, "user.name")); // "Tom"
|
|
74
|
-
```
|
|
75
|
-
|
|
76
40
|
## 使用说明
|
|
77
41
|
|
|
78
42
|
### 环境说明
|
|
@@ -86,7 +50,7 @@ console.log(libJsGetRowValue({ user: { name: "Tom" } }, "user.name")); // "Tom"
|
|
|
86
50
|
每个工具章节都遵循同一结构:
|
|
87
51
|
|
|
88
52
|
1. 作用说明
|
|
89
|
-
2.
|
|
53
|
+
2. 导入方式
|
|
90
54
|
3. 1 到 2 个最常见示例
|
|
91
55
|
|
|
92
56
|
如果你只想找某个工具的导入方式,可以直接看每个章节的第一段代码。
|