calc-vpd 1.0.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.
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calcVpd = void 0;
4
+ var vpd_js_1 = require("./vpd.js");
5
+ Object.defineProperty(exports, "calcVpd", { enumerable: true, get: function () { return vpd_js_1.calcVpd; } });
@@ -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;
@@ -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,2 @@
1
+ export type { VpdInput, VpdResult } from './vpd.js';
2
+ export { calcVpd } from './vpd.js';
@@ -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,43 +1,54 @@
1
1
  {
2
2
  "name": "calc-vpd",
3
- "version": "1.0.0",
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
- "engines": {
9
- "node": ">=14"
10
- },
11
- "scripts": {
12
- "precommit": "lint-staged",
13
- "fmt": "prettier --write '**/*.{js,json,md}'",
14
- "lint": "eslint --ext .js .",
15
- "test": "jest",
16
- "test:cov": "jest --coverage --ci --runInBand",
17
- "test:ci": "yarn lint && yarn test:cov",
18
- "prepare": "husky install"
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
- "index.js"
22
+ "lib"
28
23
  ],
29
24
  "keywords": [
30
25
  "vpd",
31
26
  "IoT",
32
27
  "aguri"
33
28
  ],
34
- "dependencies": {},
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
- "eslint": "8.18.0",
37
- "eslint-config-nzap": "5.3.2",
38
- "husky": "8.0.1",
39
- "jest": "28.1.2",
40
- "lint-staged": "13.0.3",
41
- "prettier": "2.7.1"
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"
42
53
  }
43
54
  }
package/readme.md CHANGED
@@ -1,33 +1,39 @@
1
1
  # calc-vpd
2
2
 
3
- ![Node.js CI](https://github.com/elzup/calc-vpd/workflows/Node.js%20CI/badge.svg)
4
- [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)
3
+ ![Node CI](https://github.com/elzup/calc-vpd/workflows/Node%20CI/badge.svg)
5
4
 
6
- > VPD (Vapor Pressure Deficit) function
5
+ > VPD (Vapor Pressure Deficit / 飽差) function
7
6
 
8
- - 水蒸気圧 = 6.1078 \* 10 ^ ((7.5 - 気温 / (気温 + 237.3)))
9
- - 飽和水蒸気量 = 217 - 水蒸気圧 / (気温 + 273.15)
10
- - 飽差 = (100 - 相対湿度) \* 飽和水蒸気量 / 100
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
 
17
+ ```sh
18
+ npm install calc-vpd
19
+ # or: pnpm add calc-vpd
16
20
  ```
17
- $ npm install calc-vpd
18
- ```
21
+
22
+ ESM / CommonJS / 型定義に対応。
19
23
 
20
24
  ## Usage
21
25
 
22
- ```js
23
- const calcVpd = require('calc-vpd')
26
+ ```ts
27
+ // ESM / TypeScript
28
+ import { calcVpd } from 'calc-vpd'
24
29
 
25
30
  calcVpd({ tmp: 29.2, hmd: 76.5 })
26
- //=> {
27
- // "swv": 29.080252344,
28
- // "vp": 40.518038231,
29
- // "vpd": 6.833859301,
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,18 +42,21 @@ calcVpd({ tmp: 29.2, hmd: 76.5 })
36
42
 
37
43
  #### input
38
44
 
39
- Type: `{ tmp: number, hmd: number }`
45
+ Type: `{ tmp: number; hmd: number }`
46
+
47
+ - `tmp`: 気温 (℃)
48
+ - `hmd`: 相対湿度 (%)
49
+
50
+ `tmp` / `hmd` が number でない場合は `TypeError` を投げます。
40
51
 
41
- tmp: 気温
42
- hmd: 湿度
52
+ #### returns
43
53
 
44
- #### output
54
+ Type: `{ vp: number; swv: number; vpd: number }`
45
55
 
46
- Type: `{ swv: number, vp: number, vpd number }`<br>
56
+ - `vp`: 水蒸気圧
57
+ - `swv`: 飽和水蒸気量
58
+ - `vpd`: 飽差 (Vapor Pressure Deficit)
47
59
 
48
- vp: 水蒸気圧,
49
- swv: 飽和水蒸気量,
50
- vpd: 飽差
51
60
 
52
61
  ## License
53
62
 
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
- }