@did-pay/util 1.12.37 → 1.12.39

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/constant.js ADDED
@@ -0,0 +1,13 @@
1
+ const ORDER_STATUS = Object.freeze({
2
+ preCreation: 0,
3
+ created: 10
4
+ });
5
+ const DURATION_UNIT_SYMBOL = Object.freeze({
6
+ d: "d",
7
+ M: "M",
8
+ Y: "Y"
9
+ });
10
+ export {
11
+ DURATION_UNIT_SYMBOL,
12
+ ORDER_STATUS
13
+ };
@@ -0,0 +1,14 @@
1
+ import moment from "moment";
2
+ const calExpirationTime = (duration, currentTime) => {
3
+ const now = moment(currentTime);
4
+ let result = now.add(duration.value, duration.unit);
5
+ if (result.format("HH:mm:ss") !== "00:00:00") {
6
+ result = result.add(1, "d");
7
+ }
8
+ return moment(result.format("YYYY-MM-DD 00:00:00")).toISOString();
9
+ };
10
+ const getExpirationDateDisplay = (expirationDate) => moment(expirationDate).subtract(1, "second").toISOString();
11
+ export {
12
+ calExpirationTime,
13
+ getExpirationDateDisplay
14
+ };
package/es/nft.js ADDED
@@ -0,0 +1,25 @@
1
+ import last from "lodash/last";
2
+ import get from "lodash/get";
3
+ import moment from "moment";
4
+ const getNftExpirationDate = (asset) => last(get(asset, "data.value.expirationDate", []));
5
+ const isNFTExpired = (asset) => {
6
+ const expirationDate = getNftExpirationDate(asset);
7
+ return isDateExpired(expirationDate);
8
+ };
9
+ const isDateExpired = (expirationDate) => !!expirationDate && new Date(expirationDate).getTime() <= Date.now();
10
+ const canRenewExpiredNFT = (expirationDate, retainDays) => {
11
+ const isExpired = isDateExpired(expirationDate);
12
+ if (!isExpired) {
13
+ return false;
14
+ }
15
+ if (!retainDays || retainDays <= 0) {
16
+ return false;
17
+ }
18
+ return moment(expirationDate).add(retainDays, "days").isAfter(moment());
19
+ };
20
+ export {
21
+ canRenewExpiredNFT,
22
+ getNftExpirationDate,
23
+ isDateExpired,
24
+ isNFTExpired
25
+ };
package/es/price.js ADDED
@@ -0,0 +1,24 @@
1
+ import { BN, fromUnitToToken, fromTokenToUnit } from "@ocap/util";
2
+ import { DURATION_UNIT_SYMBOL } from "./constant";
3
+ const DAYS_OF_MONTH = 30;
4
+ const DAYS_OF_YEAR = 365;
5
+ const UNIT_MAP = {
6
+ [DURATION_UNIT_SYMBOL.d]: 1,
7
+ [DURATION_UNIT_SYMBOL.M]: DAYS_OF_MONTH,
8
+ [DURATION_UNIT_SYMBOL.Y]: DAYS_OF_YEAR
9
+ };
10
+ const getPrice = (unitPrice, unit) => {
11
+ const days = UNIT_MAP[unit];
12
+ const unitPriceBN = new BN(fromTokenToUnit(unitPrice));
13
+ const unitBN = new BN(days);
14
+ return unitPriceBN.mul(unitBN);
15
+ };
16
+ const calculatePrice = (duration, unitPrice) => {
17
+ const priceBN = getPrice(unitPrice, duration.unit);
18
+ const durationBN = new BN(duration.value);
19
+ const total = priceBN.mul(durationBN).toString();
20
+ return Number(fromUnitToToken(total).toString());
21
+ };
22
+ export {
23
+ calculatePrice
24
+ };
package/lib/constant.js CHANGED
@@ -1,12 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1
3
  const ORDER_STATUS = Object.freeze({
2
4
  preCreation: 0,
3
- created: 10,
5
+ created: 10
4
6
  });
5
-
6
7
  const DURATION_UNIT_SYMBOL = Object.freeze({
7
- d: 'd',
8
- M: 'M',
9
- Y: 'Y',
8
+ d: "d",
9
+ M: "M",
10
+ Y: "Y"
10
11
  });
11
-
12
- module.exports = { ORDER_STATUS, DURATION_UNIT_SYMBOL };
12
+ exports.DURATION_UNIT_SYMBOL = DURATION_UNIT_SYMBOL;
13
+ exports.ORDER_STATUS = ORDER_STATUS;
package/lib/expiration.js CHANGED
@@ -1,20 +1,14 @@
1
- const moment = require('moment');
2
-
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const moment = require("moment");
3
4
  const calExpirationTime = (duration, currentTime) => {
4
5
  const now = moment(currentTime);
5
6
  let result = now.add(duration.value, duration.unit);
6
-
7
- // 如果续期后过期时间不是当前的 24 点,则加一天, 最后会取加 1 天后的 0 点
8
- if (result.format('HH:mm:ss') !== '00:00:00') {
9
- result = result.add(1, 'd');
7
+ if (result.format("HH:mm:ss") !== "00:00:00") {
8
+ result = result.add(1, "d");
10
9
  }
11
-
12
- return moment(result.format('YYYY-MM-DD 00:00:00')).toISOString();
13
- };
14
-
15
- const getExpirationDateDisplay = (expirationDate) => moment(expirationDate).subtract(1, 'second').toISOString();
16
-
17
- module.exports = {
18
- calExpirationTime,
19
- getExpirationDateDisplay,
10
+ return moment(result.format("YYYY-MM-DD 00:00:00")).toISOString();
20
11
  };
12
+ const getExpirationDateDisplay = (expirationDate) => moment(expirationDate).subtract(1, "second").toISOString();
13
+ exports.calExpirationTime = calExpirationTime;
14
+ exports.getExpirationDateDisplay = getExpirationDateDisplay;
package/lib/nft.js CHANGED
@@ -1,27 +1,25 @@
1
- const last = require('lodash/last');
2
- const get = require('lodash/get');
3
- const moment = require('moment');
4
-
5
- const getNftExpirationDate = (asset) => last(get(asset, 'data.value.expirationDate', []));
6
-
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const last = require("lodash/last");
4
+ const get = require("lodash/get");
5
+ const moment = require("moment");
6
+ const getNftExpirationDate = (asset) => last(get(asset, "data.value.expirationDate", []));
7
7
  const isNFTExpired = (asset) => {
8
8
  const expirationDate = getNftExpirationDate(asset);
9
9
  return isDateExpired(expirationDate);
10
10
  };
11
-
12
11
  const isDateExpired = (expirationDate) => !!expirationDate && new Date(expirationDate).getTime() <= Date.now();
13
-
14
12
  const canRenewExpiredNFT = (expirationDate, retainDays) => {
15
13
  const isExpired = isDateExpired(expirationDate);
16
14
  if (!isExpired) {
17
15
  return false;
18
16
  }
19
-
20
17
  if (!retainDays || retainDays <= 0) {
21
18
  return false;
22
19
  }
23
-
24
- return moment(expirationDate).add(retainDays, 'days').isAfter(moment());
20
+ return moment(expirationDate).add(retainDays, "days").isAfter(moment());
25
21
  };
26
-
27
- module.exports = { isNFTExpired, getNftExpirationDate, isDateExpired, canRenewExpiredNFT };
22
+ exports.canRenewExpiredNFT = canRenewExpiredNFT;
23
+ exports.getNftExpirationDate = getNftExpirationDate;
24
+ exports.isDateExpired = isDateExpired;
25
+ exports.isNFTExpired = isNFTExpired;
package/lib/price.js CHANGED
@@ -1,35 +1,24 @@
1
- const { BN, fromUnitToToken, fromTokenToUnit } = require('@ocap/util');
2
- const { DURATION_UNIT_SYMBOL } = require('./constant');
3
-
4
- const DAYS_OF_MONTH = 30; // 30 days per month
5
- const DAYS_OF_YEAR = 365; // 12 month per year
6
-
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const util = require("@ocap/util");
4
+ const constant = require("./constant");
5
+ const DAYS_OF_MONTH = 30;
6
+ const DAYS_OF_YEAR = 365;
7
7
  const UNIT_MAP = {
8
- [DURATION_UNIT_SYMBOL.d]: 1,
9
- [DURATION_UNIT_SYMBOL.M]: DAYS_OF_MONTH,
10
- [DURATION_UNIT_SYMBOL.Y]: DAYS_OF_YEAR,
8
+ [constant.DURATION_UNIT_SYMBOL.d]: 1,
9
+ [constant.DURATION_UNIT_SYMBOL.M]: DAYS_OF_MONTH,
10
+ [constant.DURATION_UNIT_SYMBOL.Y]: DAYS_OF_YEAR
11
11
  };
12
-
13
- /*
14
- *
15
- * @param {Number} unitPrice
16
- * @param {(d|M|y)} unit
17
- */
18
12
  const getPrice = (unitPrice, unit) => {
19
13
  const days = UNIT_MAP[unit];
20
-
21
- const unitPriceBN = new BN(fromTokenToUnit(unitPrice));
22
- const unitBN = new BN(days);
23
-
14
+ const unitPriceBN = new util.BN(util.fromTokenToUnit(unitPrice));
15
+ const unitBN = new util.BN(days);
24
16
  return unitPriceBN.mul(unitBN);
25
17
  };
26
-
27
18
  const calculatePrice = (duration, unitPrice) => {
28
19
  const priceBN = getPrice(unitPrice, duration.unit);
29
- const durationBN = new BN(duration.value);
20
+ const durationBN = new util.BN(duration.value);
30
21
  const total = priceBN.mul(durationBN).toString();
31
-
32
- return Number(fromUnitToToken(total).toString());
22
+ return Number(util.fromUnitToToken(total).toString());
33
23
  };
34
-
35
- module.exports = { calculatePrice };
24
+ exports.calculatePrice = calculatePrice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@did-pay/util",
3
- "version": "1.12.37",
3
+ "version": "1.12.39",
4
4
  "description": "Common library",
5
5
  "keywords": [
6
6
  "util"
@@ -11,6 +11,7 @@
11
11
  "main": "lib/util.js",
12
12
  "files": [
13
13
  "lib",
14
+ "es",
14
15
  "LICENSE",
15
16
  "package.json",
16
17
  "README.md"
@@ -23,7 +24,9 @@
23
24
  "url": "git+https://github.com/blocklet/payment-kit.git"
24
25
  },
25
26
  "scripts": {
26
- "lint": "eslint lib",
27
+ "build": "vite build",
28
+ "watch": "vite build --watch",
29
+ "lint": "eslint src",
27
30
  "lint:fix": "npm run lint -- --fix",
28
31
  "test": "node jest.js --runInBand",
29
32
  "coverage": "npm run test -- --coverage"
@@ -32,9 +35,13 @@
32
35
  "url": "https://github.com/blocklet/payment-kit/issues"
33
36
  },
34
37
  "dependencies": {
35
- "@ocap/util": "^1.18.87",
38
+ "@ocap/util": "^1.18.89",
36
39
  "lodash": "^4.17.21",
37
40
  "moment": "^2.29.4"
38
41
  },
39
- "gitHead": "4c299838afd228c832b3693d4c334620d24d464d"
42
+ "devDependencies": {
43
+ "vite": "^4.4.7",
44
+ "vite-plugin-build": "^0.10.0"
45
+ },
46
+ "gitHead": "b05121ee1ef573547265f2fd25bf89727dda6424"
40
47
  }