calc-vpd 0.2.0 → 2.0.0
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/lib/cjs/index.js +5 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/vpd.js +22 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/vpd.js +18 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/vpd.d.ts +22 -0
- package/package.json +37 -27
- package/readme.md +32 -36
- package/index.js +0 -21
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/lib/cjs/vpd.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calcVpd = void 0;
|
|
4
|
+
const floor8 = (n) => Math.round(n * 10 ** 9) / 10 ** 9;
|
|
5
|
+
/**
|
|
6
|
+
* VPD (Vapor Pressure Deficit / 飽差) を気温・相対湿度から求める。
|
|
7
|
+
*
|
|
8
|
+
* - 水蒸気圧 vp = 6.1078 * 10 ^ (7.5 * 気温 / (気温 + 237.3))
|
|
9
|
+
* - 飽和水蒸気量 swv = 217 * vp / (気温 + 273.15)
|
|
10
|
+
* - 飽差 vpd = (100 - 相対湿度) * swv / 100
|
|
11
|
+
*/
|
|
12
|
+
const calcVpd = (input) => {
|
|
13
|
+
const { tmp, hmd } = input ?? {};
|
|
14
|
+
if (typeof tmp !== 'number' || typeof hmd !== 'number') {
|
|
15
|
+
throw new TypeError(`Expected a { tmp: number, hmd: number }, got ${typeof tmp} ${typeof hmd}`);
|
|
16
|
+
}
|
|
17
|
+
const vp = floor8(6.1078 * 10 ** ((7.5 * tmp) / (tmp + 237.3)));
|
|
18
|
+
const swv = floor8((217 * vp) / (tmp + 273.15));
|
|
19
|
+
const vpd = floor8(((100 - hmd) * swv) / 100);
|
|
20
|
+
return { vp, swv, vpd };
|
|
21
|
+
};
|
|
22
|
+
exports.calcVpd = calcVpd;
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { calcVpd } from './vpd.js';
|
package/lib/esm/vpd.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const floor8 = (n) => Math.round(n * 10 ** 9) / 10 ** 9;
|
|
2
|
+
/**
|
|
3
|
+
* VPD (Vapor Pressure Deficit / 飽差) を気温・相対湿度から求める。
|
|
4
|
+
*
|
|
5
|
+
* - 水蒸気圧 vp = 6.1078 * 10 ^ (7.5 * 気温 / (気温 + 237.3))
|
|
6
|
+
* - 飽和水蒸気量 swv = 217 * vp / (気温 + 273.15)
|
|
7
|
+
* - 飽差 vpd = (100 - 相対湿度) * swv / 100
|
|
8
|
+
*/
|
|
9
|
+
export const calcVpd = (input) => {
|
|
10
|
+
const { tmp, hmd } = input ?? {};
|
|
11
|
+
if (typeof tmp !== 'number' || typeof hmd !== 'number') {
|
|
12
|
+
throw new TypeError(`Expected a { tmp: number, hmd: number }, got ${typeof tmp} ${typeof hmd}`);
|
|
13
|
+
}
|
|
14
|
+
const vp = floor8(6.1078 * 10 ** ((7.5 * tmp) / (tmp + 237.3)));
|
|
15
|
+
const swv = floor8((217 * vp) / (tmp + 273.15));
|
|
16
|
+
const vpd = floor8(((100 - hmd) * swv) / 100);
|
|
17
|
+
return { vp, swv, vpd };
|
|
18
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type VpdInput = {
|
|
2
|
+
/** 気温 (℃) */
|
|
3
|
+
tmp: number;
|
|
4
|
+
/** 相対湿度 (%) */
|
|
5
|
+
hmd: number;
|
|
6
|
+
};
|
|
7
|
+
export type VpdResult = {
|
|
8
|
+
/** 水蒸気圧 */
|
|
9
|
+
vp: number;
|
|
10
|
+
/** 飽和水蒸気量 */
|
|
11
|
+
swv: number;
|
|
12
|
+
/** 飽差 (Vapor Pressure Deficit) */
|
|
13
|
+
vpd: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* VPD (Vapor Pressure Deficit / 飽差) を気温・相対湿度から求める。
|
|
17
|
+
*
|
|
18
|
+
* - 水蒸気圧 vp = 6.1078 * 10 ^ (7.5 * 気温 / (気温 + 237.3))
|
|
19
|
+
* - 飽和水蒸気量 swv = 217 * vp / (気温 + 273.15)
|
|
20
|
+
* - 飽差 vpd = (100 - 相対湿度) * swv / 100
|
|
21
|
+
*/
|
|
22
|
+
export declare const calcVpd: (input: VpdInput) => VpdResult;
|
package/package.json
CHANGED
|
@@ -1,44 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "calc-vpd",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "VPD (Vapor Pressure Deficit) function",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "elzup/calc-vpd",
|
|
7
7
|
"author": "elzup",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
"lint-staged": {
|
|
21
|
-
"*.{js,json,md}": [
|
|
22
|
-
"prettier --write",
|
|
23
|
-
"git add"
|
|
24
|
-
]
|
|
8
|
+
"type": "module",
|
|
9
|
+
"packageManager": "pnpm@10.26.2",
|
|
10
|
+
"main": "lib/cjs/index.js",
|
|
11
|
+
"module": "lib/esm/index.js",
|
|
12
|
+
"types": "lib/types/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./lib/types/index.d.ts",
|
|
16
|
+
"import": "./lib/esm/index.js",
|
|
17
|
+
"require": "./lib/cjs/index.js"
|
|
18
|
+
}
|
|
25
19
|
},
|
|
20
|
+
"sideEffects": false,
|
|
26
21
|
"files": [
|
|
27
|
-
"
|
|
22
|
+
"lib"
|
|
28
23
|
],
|
|
29
24
|
"keywords": [
|
|
30
25
|
"vpd",
|
|
31
26
|
"IoT",
|
|
32
27
|
"aguri"
|
|
33
28
|
],
|
|
34
|
-
"
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"clean": "rm -rf lib",
|
|
34
|
+
"build": "pnpm clean && pnpm build:cjs && pnpm build:esm && pnpm build:types",
|
|
35
|
+
"build:cjs": "tsc --module commonjs --moduleResolution node10 --declaration false --outDir lib/cjs && echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json",
|
|
36
|
+
"build:esm": "tsc --module esnext --moduleResolution bundler --declaration false --outDir lib/esm",
|
|
37
|
+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir lib/types",
|
|
38
|
+
"lint": "biome check .",
|
|
39
|
+
"lint:fix": "biome check --write .",
|
|
40
|
+
"fmt": "biome format --write .",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"test:watch": "vitest",
|
|
43
|
+
"test:cov": "vitest run --coverage",
|
|
44
|
+
"prepare": "git config core.hooksPath .githooks || true",
|
|
45
|
+
"prepublishOnly": "pnpm build && pnpm test"
|
|
46
|
+
},
|
|
35
47
|
"devDependencies": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"lint-staged": "10.2.11",
|
|
42
|
-
"prettier": "2.0.5"
|
|
48
|
+
"@biomejs/biome": "2.4.10",
|
|
49
|
+
"@types/node": "22.10.2",
|
|
50
|
+
"@vitest/coverage-v8": "2.1.8",
|
|
51
|
+
"typescript": "5.7.2",
|
|
52
|
+
"vitest": "2.1.8"
|
|
43
53
|
}
|
|
44
54
|
}
|
package/readme.md
CHANGED
|
@@ -1,33 +1,39 @@
|
|
|
1
1
|
# calc-vpd
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://github.com/facebook/jest)
|
|
3
|
+

|
|
5
4
|
|
|
6
|
-
> VPD (Vapor Pressure Deficit) function
|
|
5
|
+
> VPD (Vapor Pressure Deficit / 飽差) function
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
気温と相対湿度から水蒸気圧・飽和水蒸気量・飽差を計算します。
|
|
8
|
+
|
|
9
|
+
- 水蒸気圧 vp = 6.1078 \* 10 ^ (7.5 \* 気温 / (気温 + 237.3))
|
|
10
|
+
- 飽和水蒸気量 swv = 217 \* vp / (気温 + 273.15)
|
|
11
|
+
- 飽差 vpd = (100 - 相対湿度) \* swv / 100
|
|
11
12
|
|
|
12
13
|
参考: http://bigbearfarm.blog.fc2.com/blog-entry-306.html
|
|
13
14
|
|
|
14
15
|
## Install
|
|
15
16
|
|
|
16
|
-
```
|
|
17
|
-
|
|
17
|
+
```sh
|
|
18
|
+
npm install calc-vpd
|
|
19
|
+
# or: pnpm add calc-vpd
|
|
18
20
|
```
|
|
19
21
|
|
|
22
|
+
ESM / CommonJS / 型定義に対応。
|
|
23
|
+
|
|
20
24
|
## Usage
|
|
21
25
|
|
|
22
|
-
```
|
|
23
|
-
|
|
26
|
+
```ts
|
|
27
|
+
// ESM / TypeScript
|
|
28
|
+
import { calcVpd } from 'calc-vpd'
|
|
24
29
|
|
|
25
30
|
calcVpd({ tmp: 29.2, hmd: 76.5 })
|
|
26
|
-
//=> {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
+
//=> { vp: 40.518038231, swv: 29.080252344, vpd: 6.833859301 }
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
// CommonJS
|
|
36
|
+
const { calcVpd } = require('calc-vpd')
|
|
31
37
|
```
|
|
32
38
|
|
|
33
39
|
## API
|
|
@@ -36,32 +42,22 @@ calcVpd({ tmp: 29.2, hmd: 76.5 })
|
|
|
36
42
|
|
|
37
43
|
#### input
|
|
38
44
|
|
|
39
|
-
Type: `{ tmp: number
|
|
45
|
+
Type: `{ tmp: number; hmd: number }`
|
|
40
46
|
|
|
41
|
-
tmp
|
|
42
|
-
hmd
|
|
47
|
+
- `tmp`: 気温 (℃)
|
|
48
|
+
- `hmd`: 相対湿度 (%)
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
`tmp` / `hmd` が number でない場合は `TypeError` を投げます。
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
#### returns
|
|
47
53
|
|
|
48
|
-
vp:
|
|
49
|
-
swv: 飽和水蒸気量,
|
|
50
|
-
vpd: 飽差
|
|
54
|
+
Type: `{ vp: number; swv: number; vpd: number }`
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
## Contributors
|
|
56
|
+
- `vp`: 水蒸気圧
|
|
57
|
+
- `swv`: 飽和水蒸気量
|
|
58
|
+
- `vpd`: 飽差 (Vapor Pressure Deficit)
|
|
57
59
|
|
|
58
|
-
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
<!-- prettier-ignore -->
|
|
62
|
-
| [<img src="https://avatars3.githubusercontent.com/u/2284908?v=4" width="100px;"/><br /><sub><b>elzup</b></sub>](https://elzup.com)<br />[💻](https://github.com/elzup/calc-vpd/commits?author=elzup "Code") |
|
|
63
|
-
| :---: |
|
|
64
|
-
|
|
65
|
-
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
61
|
+
## License
|
|
66
62
|
|
|
67
|
-
|
|
63
|
+
MIT © [elzup](https://elzup.com)
|
package/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const floor8 = n => Math.round(n * 10 ** 9) / 10 ** 9
|
|
4
|
-
|
|
5
|
-
module.exports = (input /*: { tmp: number, hmd: number } */) => {
|
|
6
|
-
const { tmp, hmd } = input || {}
|
|
7
|
-
|
|
8
|
-
if (typeof tmp !== 'number' || typeof hmd !== 'number') {
|
|
9
|
-
throw new TypeError(
|
|
10
|
-
`Expected a { tmp: number, hmd: number }, got ${typeof tmp} ${typeof hmd}`
|
|
11
|
-
)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// vaporPressur
|
|
15
|
-
const vp = floor8(6.1078 * Math.pow(10, (7.5 * tmp) / (tmp + 237.3)))
|
|
16
|
-
const swv = floor8((217 * vp) / (tmp + 273.15))
|
|
17
|
-
// amount of saturated water vapor
|
|
18
|
-
const vpd = floor8(((100 - hmd) * swv) / 100)
|
|
19
|
-
|
|
20
|
-
return { vp, swv, vpd }
|
|
21
|
-
}
|