@lingui/message-utils 4.5.0 → 4.6.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.
@@ -1,5 +1,5 @@
1
1
  type CompiledIcuChoices = Record<string, CompiledMessage> & {
2
- offset: number;
2
+ offset: number | undefined;
3
3
  };
4
4
  type CompiledMessageToken = string | [name: string, type?: string, format?: null | string | CompiledIcuChoices];
5
5
  type CompiledMessage = string | CompiledMessageToken[];
@@ -1,5 +1,5 @@
1
1
  type CompiledIcuChoices = Record<string, CompiledMessage> & {
2
- offset: number;
2
+ offset: number | undefined;
3
3
  };
4
4
  type CompiledMessageToken = string | [name: string, type?: string, format?: null | string | CompiledIcuChoices];
5
5
  type CompiledMessage = string | CompiledMessageToken[];
@@ -1,5 +1,5 @@
1
1
  type CompiledIcuChoices = Record<string, CompiledMessage> & {
2
- offset: number;
2
+ offset: number | undefined;
3
3
  };
4
4
  type CompiledMessageToken = string | [name: string, type?: string, format?: null | string | CompiledIcuChoices];
5
5
  type CompiledMessage = string | CompiledMessageToken[];
@@ -1,14 +1,17 @@
1
1
  'use strict';
2
2
 
3
- const crypto = require('crypto');
4
-
5
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
6
-
7
- const crypto__default = /*#__PURE__*/_interopDefaultCompat(crypto);
3
+ const jsSha256 = require('js-sha256');
8
4
 
9
5
  const UNIT_SEPARATOR = "";
10
6
  function generateMessageId(msg, context = "") {
11
- return crypto__default.createHash("sha256").update(msg + UNIT_SEPARATOR + (context || "")).digest("base64").slice(0, 6);
7
+ return hexToBase64(jsSha256.sha256(msg + UNIT_SEPARATOR + (context || ""))).slice(0, 6);
8
+ }
9
+ function hexToBase64(hexStr) {
10
+ let base64 = "";
11
+ for (let i = 0; i < hexStr.length; i++) {
12
+ base64 += !(i - 1 & 1) ? String.fromCharCode(parseInt(hexStr.substring(i - 1, i + 1), 16)) : "";
13
+ }
14
+ return btoa(base64);
12
15
  }
13
16
 
14
17
  exports.generateMessageId = generateMessageId;
@@ -1,8 +1,15 @@
1
- import crypto from 'crypto';
1
+ import { sha256 } from 'js-sha256';
2
2
 
3
3
  const UNIT_SEPARATOR = "";
4
4
  function generateMessageId(msg, context = "") {
5
- return crypto.createHash("sha256").update(msg + UNIT_SEPARATOR + (context || "")).digest("base64").slice(0, 6);
5
+ return hexToBase64(sha256(msg + UNIT_SEPARATOR + (context || ""))).slice(0, 6);
6
+ }
7
+ function hexToBase64(hexStr) {
8
+ let base64 = "";
9
+ for (let i = 0; i < hexStr.length; i++) {
10
+ base64 += !(i - 1 & 1) ? String.fromCharCode(parseInt(hexStr.substring(i - 1, i + 1), 16)) : "";
11
+ }
12
+ return btoa(base64);
6
13
  }
7
14
 
8
15
  export { generateMessageId };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/message-utils",
3
- "version": "4.5.0",
3
+ "version": "4.6.0",
4
4
  "license": "MIT",
5
5
  "keywords": [],
6
6
  "sideEffects": false,
@@ -47,11 +47,12 @@
47
47
  "generateMessageId.js"
48
48
  ],
49
49
  "dependencies": {
50
- "@messageformat/parser": "^5.0.0"
50
+ "@messageformat/parser": "^5.0.0",
51
+ "js-sha256": "^0.10.1"
51
52
  },
52
53
  "devDependencies": {
53
54
  "@lingui/jest-mocks": "^3.0.3",
54
55
  "unbuild": "2.0.0"
55
56
  },
56
- "gitHead": "62c92d1f8c60b3890bdda870f307fa780d423080"
57
+ "gitHead": "2afa0efb2d0cd1d47adc76e1eec9f5e57e34ae18"
57
58
  }