hsu-utils 0.0.14 → 0.0.16

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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  *
3
- * hsu-utils v0.0.13
3
+ * hsu-utils v0.0.15
4
4
  *
5
5
  * some front-end utils
6
6
  *
@@ -0,0 +1 @@
1
+ export default function array_is_includes<T>(arr1: Array<T>, arr2: Array<T>): boolean;
@@ -0,0 +1,8 @@
1
+ import { Equal } from '..';
2
+ export default function array_is_includes(arr1, arr2) {
3
+ const largeArr = arr1.length >= arr2.length ? arr1 : arr2;
4
+ const smallArr = arr1.length < arr2.length ? arr1 : arr2;
5
+ return smallArr.every((item) => {
6
+ return !!largeArr.find((i) => Equal.ValEqual(item, i));
7
+ });
8
+ }
@@ -6,5 +6,5 @@ interface Font {
6
6
  lineHeight?: number;
7
7
  family?: string;
8
8
  }
9
- export default function get_string_width(str: string, font?: Font): number;
9
+ export default function get_string_width(str: string, font?: Font, letterSpacing?: number): number;
10
10
  export {};
@@ -1,9 +1,11 @@
1
- export default function get_string_width(str, font = {}) {
1
+ export default function get_string_width(str, font = {}, letterSpacing = 0) {
2
2
  const { style = 'normal', variant = 'normal', weight = 'normal', size = 12, lineHeight = 1, family: fontFamily = '微软雅黑' } = font;
3
3
  const canvas = document.createElement('canvas');
4
4
  const ctx = canvas.getContext('2d');
5
5
  ctx.font = `${style} ${variant} ${weight} ${size}px/${lineHeight} ${fontFamily}`;
6
6
  const metrics = ctx.measureText(str);
7
- const width = +(+metrics.width.toFixed(2) + 0.01).toFixed(2);
7
+ let width = +(+metrics.width.toFixed(2) + 0.01).toFixed(2);
8
+ const _letterSpacing = (str.length > 0 ? str.length - 1 : 0) * letterSpacing;
9
+ width += _letterSpacing;
8
10
  return width;
9
11
  }
package/es/index.d.ts CHANGED
@@ -7,6 +7,7 @@ import ConvertNumbers from './ConvertNumbers';
7
7
  import loadImage from './LoadImage';
8
8
  import renderPDF from './RenderPDF';
9
9
  import downloadFile from './DownloadFile';
10
- export { console_table, deepCopy, Equal, Typeof, get_string_width, ConvertNumbers, loadImage, renderPDF, downloadFile };
10
+ import array_is_includes from './ArrayIsIncludes';
11
+ export { console_table, deepCopy, Equal, Typeof, get_string_width, ConvertNumbers, loadImage, renderPDF, downloadFile, array_is_includes };
11
12
  import { ConsoleData } from './ConsoleTable';
12
13
  export type { ConsoleData };
package/es/index.js CHANGED
@@ -7,4 +7,5 @@ import ConvertNumbers from './ConvertNumbers';
7
7
  import loadImage from './LoadImage';
8
8
  import renderPDF from './RenderPDF';
9
9
  import downloadFile from './DownloadFile';
10
- export { console_table, deepCopy, Equal, Typeof, get_string_width, ConvertNumbers, loadImage, renderPDF, downloadFile };
10
+ import array_is_includes from './ArrayIsIncludes';
11
+ export { console_table, deepCopy, Equal, Typeof, get_string_width, ConvertNumbers, loadImage, renderPDF, downloadFile, array_is_includes };
@@ -0,0 +1 @@
1
+ export default function array_is_includes<T>(arr1: Array<T>, arr2: Array<T>): boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var __1 = require("..");
4
+ function array_is_includes(arr1, arr2) {
5
+ var largeArr = arr1.length >= arr2.length ? arr1 : arr2;
6
+ var smallArr = arr1.length < arr2.length ? arr1 : arr2;
7
+ return smallArr.every(function (item) {
8
+ return !!largeArr.find(function (i) { return __1.Equal.ValEqual(item, i); });
9
+ });
10
+ }
11
+ exports.default = array_is_includes;
@@ -6,5 +6,5 @@ interface Font {
6
6
  lineHeight?: number;
7
7
  family?: string;
8
8
  }
9
- export default function get_string_width(str: string, font?: Font): number;
9
+ export default function get_string_width(str: string, font?: Font, letterSpacing?: number): number;
10
10
  export {};
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- function get_string_width(str, font) {
3
+ function get_string_width(str, font, letterSpacing) {
4
4
  if (font === void 0) { font = {}; }
5
+ if (letterSpacing === void 0) { letterSpacing = 0; }
5
6
  var _a = font.style, style = _a === void 0 ? 'normal' : _a, _b = font.variant, variant = _b === void 0 ? 'normal' : _b, _c = font.weight, weight = _c === void 0 ? 'normal' : _c, _d = font.size, size = _d === void 0 ? 12 : _d, _e = font.lineHeight, lineHeight = _e === void 0 ? 1 : _e, _f = font.family, fontFamily = _f === void 0 ? '微软雅黑' : _f;
6
7
  var canvas = document.createElement('canvas');
7
8
  var ctx = canvas.getContext('2d');
8
9
  ctx.font = "".concat(style, " ").concat(variant, " ").concat(weight, " ").concat(size, "px/").concat(lineHeight, " ").concat(fontFamily);
9
10
  var metrics = ctx.measureText(str);
10
11
  var width = +(+metrics.width.toFixed(2) + 0.01).toFixed(2);
12
+ var _letterSpacing = (str.length > 0 ? str.length - 1 : 0) * letterSpacing;
13
+ width += _letterSpacing;
11
14
  return width;
12
15
  }
13
16
  exports.default = get_string_width;
package/lib/index.d.ts CHANGED
@@ -7,6 +7,7 @@ import ConvertNumbers from './ConvertNumbers';
7
7
  import loadImage from './LoadImage';
8
8
  import renderPDF from './RenderPDF';
9
9
  import downloadFile from './DownloadFile';
10
- export { console_table, deepCopy, Equal, Typeof, get_string_width, ConvertNumbers, loadImage, renderPDF, downloadFile };
10
+ import array_is_includes from './ArrayIsIncludes';
11
+ export { console_table, deepCopy, Equal, Typeof, get_string_width, ConvertNumbers, loadImage, renderPDF, downloadFile, array_is_includes };
11
12
  import { ConsoleData } from './ConsoleTable';
12
13
  export type { ConsoleData };
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.downloadFile = exports.renderPDF = exports.loadImage = exports.ConvertNumbers = exports.get_string_width = exports.Typeof = exports.Equal = exports.deepCopy = exports.console_table = void 0;
6
+ exports.array_is_includes = exports.downloadFile = exports.renderPDF = exports.loadImage = exports.ConvertNumbers = exports.get_string_width = exports.Typeof = exports.Equal = exports.deepCopy = exports.console_table = void 0;
7
7
  var ConsoleTable_1 = __importDefault(require("./ConsoleTable"));
8
8
  exports.console_table = ConsoleTable_1.default;
9
9
  var DeepCopy_1 = __importDefault(require("./DeepCopy"));
@@ -22,3 +22,5 @@ var RenderPDF_1 = __importDefault(require("./RenderPDF"));
22
22
  exports.renderPDF = RenderPDF_1.default;
23
23
  var DownloadFile_1 = __importDefault(require("./DownloadFile"));
24
24
  exports.downloadFile = DownloadFile_1.default;
25
+ var ArrayIsIncludes_1 = __importDefault(require("./ArrayIsIncludes"));
26
+ exports.array_is_includes = ArrayIsIncludes_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hsu-utils",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "some front-end utils",
5
5
  "repository": "git@github.com:VitaTsui/hsu-utils.git",
6
6
  "author": "VitaHsu <vitahsu7@gmail.com>",