@discord/intl-flat-json-parser 0.19.2-canary.9431174
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/LICENSE +21 -0
- package/README.md +37 -0
- package/index.d.ts +17 -0
- package/index.js +80 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Discord, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# intl_flat_json_parser
|
|
2
|
+
|
|
3
|
+
A Rust-based JSON parser with location information for flat objects, used by `@discord/intl-message-database` to provide more accurate diagnostics for values parsed out of JSON files.
|
|
4
|
+
|
|
5
|
+
The parser is specifically built to only understand a flat, well-formed object structure and has minimal error recovery, but fully supports Unicode and other JSON string syntax like escapes.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pnpm add @discord/intl-flat-json-parser
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { parseJson, parseJsonFile } from '@discord/intl-flat-json-parser';
|
|
17
|
+
|
|
18
|
+
// Parse a string as flat JSON
|
|
19
|
+
const jsonContent = `{
|
|
20
|
+
"MESSAGE_ONE": "Hello, this is the first message",
|
|
21
|
+
"MESSAGE_TWO": "Another message!"
|
|
22
|
+
}`;
|
|
23
|
+
|
|
24
|
+
const messages = parseJson(jsonContent);
|
|
25
|
+
console.log(messages[0]);
|
|
26
|
+
//=> {
|
|
27
|
+
// key: "MESSAGE_ONE",
|
|
28
|
+
// value: "Hello, this is the first message",
|
|
29
|
+
// position: {
|
|
30
|
+
// line: 2,
|
|
31
|
+
// col: 19
|
|
32
|
+
// }
|
|
33
|
+
// }
|
|
34
|
+
|
|
35
|
+
// Or pass a file path to get parsed directly from the file system
|
|
36
|
+
const directMessages = parseJsonFile('some/file/path.json');
|
|
37
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export interface Message {
|
|
4
|
+
key: string
|
|
5
|
+
value: string
|
|
6
|
+
position: Position
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare function parseJson(text: string): Array<Message>
|
|
10
|
+
|
|
11
|
+
export declare function parseJsonFile(filePath: string): Array<Message>
|
|
12
|
+
|
|
13
|
+
export interface Position {
|
|
14
|
+
line: number
|
|
15
|
+
col: number
|
|
16
|
+
}
|
|
17
|
+
|
package/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* Originally auto-generated by NAPI-RS, adapted for working with an `npm` dir for each built package. */
|
|
5
|
+
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
|
|
9
|
+
function isMusl() {
|
|
10
|
+
// For Node 10
|
|
11
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
12
|
+
try {
|
|
13
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim();
|
|
14
|
+
return fs.readFileSync(lddPath, 'utf8').includes('musl');
|
|
15
|
+
} catch (e) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
/** @type {any} */
|
|
20
|
+
let report = process.report.getReport();
|
|
21
|
+
if (typeof report === 'string') {
|
|
22
|
+
report = JSON.parse(report);
|
|
23
|
+
}
|
|
24
|
+
const { glibcVersionRuntime } = report.header;
|
|
25
|
+
return !glibcVersionRuntime;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @type {Record<string, Record<string, string>>} */
|
|
30
|
+
const PACKAGE_NAMES = {
|
|
31
|
+
android: { arm: 'android-arm-eabi', arm64: 'android-arm64' },
|
|
32
|
+
win32: { arm64: 'win32-arm64-msvc', ia32: 'win32-ia32-msvc', x64: 'win32-x64-msvc' },
|
|
33
|
+
darwin: { arm64: 'darwin-arm64', x64: 'darwin-x64' },
|
|
34
|
+
freebsd: { x64: 'freebsd-x64' },
|
|
35
|
+
'linux-gnu': {
|
|
36
|
+
arm: 'linux-arm-gnueabihf',
|
|
37
|
+
arm64: 'linux-arm64-gnu',
|
|
38
|
+
x64: 'linux-x64-gnu',
|
|
39
|
+
riscv64: 'linux-riscv64-gnu',
|
|
40
|
+
s390x: 'linux-s390x-gnu',
|
|
41
|
+
},
|
|
42
|
+
'linux-musl': {
|
|
43
|
+
arm: 'linux-arm-musleabihf',
|
|
44
|
+
arm64: 'linux-arm64-musl',
|
|
45
|
+
x64: 'linux-x64-musl',
|
|
46
|
+
riscv64: 'linux-riscv64-musl',
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const platform =
|
|
51
|
+
process.platform !== 'linux' ? process.platform : 'linux-' + (isMusl() ? 'musl' : 'gnu');
|
|
52
|
+
const arch = process.arch;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @returns {string}
|
|
56
|
+
*/
|
|
57
|
+
function getPackageName() {
|
|
58
|
+
if (!(platform in PACKAGE_NAMES)) {
|
|
59
|
+
throw new Error(`Unsupported OS: ${platform}`);
|
|
60
|
+
}
|
|
61
|
+
if (!(arch in PACKAGE_NAMES[platform])) {
|
|
62
|
+
throw new Error(`Unsupported architecture for ${platform}: ${arch}`);
|
|
63
|
+
}
|
|
64
|
+
return PACKAGE_NAMES[platform][arch];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const packageName = getPackageName();
|
|
68
|
+
const localPath = path.join(
|
|
69
|
+
__dirname,
|
|
70
|
+
`npm/${packageName}/intl-flat-json-parser.${packageName}.node`,
|
|
71
|
+
);
|
|
72
|
+
const packagePath = `@discord/intl-flat-json-parser-${packageName}`;
|
|
73
|
+
const nativeBinding = fs.existsSync(localPath) ? require(localPath) : require(packagePath);
|
|
74
|
+
|
|
75
|
+
const { parseJson, parseJsonFile } = nativeBinding;
|
|
76
|
+
|
|
77
|
+
module.exports = {
|
|
78
|
+
parseJson,
|
|
79
|
+
parseJsonFile,
|
|
80
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@discord/intl-flat-json-parser",
|
|
3
|
+
"version": "0.19.2-canary.9431174",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Rust-based JSON parser with location information for flat objects.",
|
|
6
|
+
"author": "Jon Egeland",
|
|
7
|
+
"main": "./index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"index.d.ts",
|
|
11
|
+
"index.js"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/discord/discord-intl"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@napi-rs/cli": "^2.18.4"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">= 10"
|
|
22
|
+
},
|
|
23
|
+
"napi": {
|
|
24
|
+
"name": "intl-flat-json-parser",
|
|
25
|
+
"triples": {
|
|
26
|
+
"defaults": false,
|
|
27
|
+
"additional": [
|
|
28
|
+
"aarch64-apple-darwin",
|
|
29
|
+
"aarch64-unknown-linux-gnu",
|
|
30
|
+
"aarch64-pc-windows-msvc",
|
|
31
|
+
"x86_64-apple-darwin",
|
|
32
|
+
"x86_64-pc-windows-msvc",
|
|
33
|
+
"x86_64-unknown-linux-gnu"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build:debug": "cargo build"
|
|
39
|
+
}
|
|
40
|
+
}
|