react-native-fast-json 0.1.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.
Files changed (43) hide show
  1. package/FastJson.podspec +41 -0
  2. package/LICENSE +20 -0
  3. package/README.md +162 -0
  4. package/android/CMakeLists.txt +37 -0
  5. package/android/build.gradle +119 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/cpp/cpp-adapter.cpp +11 -0
  8. package/android/src/main/java/com/margelo/nitro/fastjson/FastJsonPackage.kt +22 -0
  9. package/cpp/HybridFastJson.cpp +61 -0
  10. package/cpp/HybridFastJson.hpp +19 -0
  11. package/cpp/HybridJsonView.cpp +370 -0
  12. package/cpp/HybridJsonView.hpp +39 -0
  13. package/cpp/third_party/simdjson.cpp +65338 -0
  14. package/cpp/third_party/simdjson.h +186793 -0
  15. package/lib/module/FastJson.nitro.js +4 -0
  16. package/lib/module/FastJson.nitro.js.map +1 -0
  17. package/lib/module/index.js +5 -0
  18. package/lib/module/index.js.map +1 -0
  19. package/lib/module/package.json +1 -0
  20. package/lib/typescript/package.json +1 -0
  21. package/lib/typescript/src/FastJson.nitro.d.ts +85 -0
  22. package/lib/typescript/src/FastJson.nitro.d.ts.map +1 -0
  23. package/lib/typescript/src/index.d.ts +4 -0
  24. package/lib/typescript/src/index.d.ts.map +1 -0
  25. package/nitro.json +19 -0
  26. package/nitrogen/generated/android/fastjson+autolinking.cmake +82 -0
  27. package/nitrogen/generated/android/fastjson+autolinking.gradle +27 -0
  28. package/nitrogen/generated/android/fastjsonOnLoad.cpp +49 -0
  29. package/nitrogen/generated/android/fastjsonOnLoad.hpp +34 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/fastjson/fastjsonOnLoad.kt +35 -0
  31. package/nitrogen/generated/ios/FastJson+autolinking.rb +62 -0
  32. package/nitrogen/generated/ios/FastJson-Swift-Cxx-Bridge.cpp +17 -0
  33. package/nitrogen/generated/ios/FastJson-Swift-Cxx-Bridge.hpp +27 -0
  34. package/nitrogen/generated/ios/FastJson-Swift-Cxx-Umbrella.hpp +38 -0
  35. package/nitrogen/generated/ios/FastJsonAutolinking.mm +35 -0
  36. package/nitrogen/generated/ios/FastJsonAutolinking.swift +16 -0
  37. package/nitrogen/generated/shared/c++/HybridFastJsonSpec.cpp +23 -0
  38. package/nitrogen/generated/shared/c++/HybridFastJsonSpec.hpp +70 -0
  39. package/nitrogen/generated/shared/c++/HybridJsonViewSpec.cpp +34 -0
  40. package/nitrogen/generated/shared/c++/HybridJsonViewSpec.hpp +81 -0
  41. package/package.json +185 -0
  42. package/src/FastJson.nitro.ts +86 -0
  43. package/src/index.tsx +6 -0
@@ -0,0 +1,34 @@
1
+ ///
2
+ /// HybridJsonViewSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridJsonViewSpec.hpp"
9
+
10
+ namespace margelo::nitro::fastjson {
11
+
12
+ void HybridJsonViewSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridGetter("type", &HybridJsonViewSpec::getType);
18
+ prototype.registerHybridSetter("type", &HybridJsonViewSpec::setType);
19
+ prototype.registerHybridGetter("length", &HybridJsonViewSpec::getLength);
20
+ prototype.registerHybridSetter("length", &HybridJsonViewSpec::setLength);
21
+ prototype.registerHybridMethod("rawJson", &HybridJsonViewSpec::rawJson);
22
+ prototype.registerHybridMethod("getValue", &HybridJsonViewSpec::getValue);
23
+ prototype.registerHybridMethod("keys", &HybridJsonViewSpec::keys);
24
+ prototype.registerHybridMethod("at", &HybridJsonViewSpec::at);
25
+ prototype.registerHybridMethod("atPath", &HybridJsonViewSpec::atPath);
26
+ prototype.registerHybridMethod("atPathWithWildcard", &HybridJsonViewSpec::atPathWithWildcard);
27
+ prototype.registerHybridMethod("asString", &HybridJsonViewSpec::asString);
28
+ prototype.registerHybridMethod("asNumber", &HybridJsonViewSpec::asNumber);
29
+ prototype.registerHybridMethod("asBoolean", &HybridJsonViewSpec::asBoolean);
30
+ prototype.registerHybridMethod("asObject", &HybridJsonViewSpec::asObject);
31
+ });
32
+ }
33
+
34
+ } // namespace margelo::nitro::fastjson
@@ -0,0 +1,81 @@
1
+ ///
2
+ /// HybridJsonViewSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `HybridJsonViewSpec` to properly resolve imports.
17
+ namespace margelo::nitro::fastjson { class HybridJsonViewSpec; }
18
+
19
+ #include <string>
20
+ #include <NitroModules/Null.hpp>
21
+ #include <memory>
22
+ #include "HybridJsonViewSpec.hpp"
23
+ #include <variant>
24
+ #include <vector>
25
+ #include <NitroModules/AnyMap.hpp>
26
+
27
+ namespace margelo::nitro::fastjson {
28
+
29
+ using namespace margelo::nitro;
30
+
31
+ /**
32
+ * An abstract base class for `JsonView`
33
+ * Inherit this class to create instances of `HybridJsonViewSpec` in C++.
34
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
35
+ * @example
36
+ * ```cpp
37
+ * class HybridJsonView: public HybridJsonViewSpec {
38
+ * public:
39
+ * HybridJsonView(...): HybridObject(TAG) { ... }
40
+ * // ...
41
+ * };
42
+ * ```
43
+ */
44
+ class HybridJsonViewSpec: public virtual HybridObject {
45
+ public:
46
+ // Constructor
47
+ explicit HybridJsonViewSpec(): HybridObject(TAG) { }
48
+
49
+ // Destructor
50
+ ~HybridJsonViewSpec() override = default;
51
+
52
+ public:
53
+ // Properties
54
+ virtual std::string getType() = 0;
55
+ virtual void setType(const std::string& type) = 0;
56
+ virtual double getLength() = 0;
57
+ virtual void setLength(double length) = 0;
58
+
59
+ public:
60
+ // Methods
61
+ virtual std::string rawJson() = 0;
62
+ virtual std::variant<nitro::NullType, std::shared_ptr<HybridJsonViewSpec>> getValue(const std::string& key) = 0;
63
+ virtual std::vector<std::string> keys() = 0;
64
+ virtual std::variant<nitro::NullType, std::shared_ptr<HybridJsonViewSpec>> at(double index) = 0;
65
+ virtual std::variant<nitro::NullType, std::shared_ptr<HybridJsonViewSpec>> atPath(const std::string& path) = 0;
66
+ virtual std::variant<nitro::NullType, std::vector<std::string>> atPathWithWildcard(const std::string& path) = 0;
67
+ virtual std::string asString() = 0;
68
+ virtual double asNumber() = 0;
69
+ virtual bool asBoolean() = 0;
70
+ virtual std::shared_ptr<AnyMap> asObject() = 0;
71
+
72
+ protected:
73
+ // Hybrid Setup
74
+ void loadHybridMethods() override;
75
+
76
+ protected:
77
+ // Tag for logging
78
+ static constexpr auto TAG = "JsonView";
79
+ };
80
+
81
+ } // namespace margelo::nitro::fastjson
package/package.json ADDED
@@ -0,0 +1,185 @@
1
+ {
2
+ "name": "react-native-fast-json",
3
+ "version": "0.1.0",
4
+ "description": "Fast JSON parsing for large files in React Native, powered by simdjson (C++ SIMD acceleration) via Nitro Modules",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "nitrogen",
22
+ "nitro.json",
23
+ "*.podspec",
24
+ "react-native.config.js",
25
+ "!ios/build",
26
+ "!android/build",
27
+ "!android/gradle",
28
+ "!android/gradlew",
29
+ "!android/gradlew.bat",
30
+ "!android/local.properties",
31
+ "!**/__tests__",
32
+ "!**/__fixtures__",
33
+ "!**/__mocks__",
34
+ "!**/.*"
35
+ ],
36
+ "scripts": {
37
+ "example": "yarn workspace react-native-fast-json-example",
38
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
39
+ "prepare": "bob build",
40
+ "nitrogen": "nitrogen",
41
+ "typecheck": "tsc",
42
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
43
+ "test": "jest",
44
+ "release": "release-it --only-version"
45
+ },
46
+ "keywords": [
47
+ "react-native",
48
+ "ios",
49
+ "android",
50
+ "json",
51
+ "json-parser",
52
+ "json-parse",
53
+ "simdjson",
54
+ "simd",
55
+ "large-json",
56
+ "fast-json",
57
+ "nitro",
58
+ "cpp"
59
+ ],
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git+https://github.com/ifeoluwak/react-native-fast-json.git"
63
+ },
64
+ "author": "ifeoluwa <ifeoluwaking24@gmail.com> (https://github.com/ifeoluwak)",
65
+ "license": "MIT",
66
+ "bugs": {
67
+ "url": "https://github.com/ifeoluwak/react-native-fast-json/issues"
68
+ },
69
+ "homepage": "https://github.com/ifeoluwak/react-native-fast-json#readme",
70
+ "publishConfig": {
71
+ "registry": "https://registry.npmjs.org/"
72
+ },
73
+ "devDependencies": {
74
+ "@commitlint/config-conventional": "^20.5.0",
75
+ "@eslint/compat": "^2.0.3",
76
+ "@eslint/eslintrc": "^3.3.5",
77
+ "@eslint/js": "^10.0.1",
78
+ "@jest/globals": "^30.0.0",
79
+ "@react-native/babel-preset": "0.85.0",
80
+ "@react-native/eslint-config": "0.85.0",
81
+ "@react-native/jest-preset": "0.85.0",
82
+ "@release-it/conventional-changelog": "^10.0.6",
83
+ "@types/react": "^19.2.0",
84
+ "commitlint": "^20.5.0",
85
+ "del-cli": "^7.0.0",
86
+ "eslint": "^9.39.4",
87
+ "eslint-config-prettier": "^10.1.8",
88
+ "eslint-plugin-ft-flow": "^3.0.11",
89
+ "eslint-plugin-prettier": "^5.5.5",
90
+ "jest": "^30.3.0",
91
+ "lefthook": "^2.1.4",
92
+ "nitrogen": "^0.35.5",
93
+ "prettier": "^3.8.1",
94
+ "react": "19.2.3",
95
+ "react-native": "0.85.0",
96
+ "react-native-builder-bob": "^0.41.0",
97
+ "react-native-nitro-modules": "^0.35.5",
98
+ "release-it": "^19.2.4",
99
+ "turbo": "^2.8.21",
100
+ "typescript": "^6.0.2"
101
+ },
102
+ "peerDependencies": {
103
+ "react": "*",
104
+ "react-native": "*",
105
+ "react-native-nitro-modules": "^0.35.5"
106
+ },
107
+ "workspaces": [
108
+ "example"
109
+ ],
110
+ "packageManager": "yarn@4.11.0",
111
+ "react-native-builder-bob": {
112
+ "source": "src",
113
+ "output": "lib",
114
+ "targets": [
115
+ [
116
+ "custom",
117
+ {
118
+ "script": "nitrogen",
119
+ "clean": "nitrogen/"
120
+ }
121
+ ],
122
+ [
123
+ "module",
124
+ {
125
+ "esm": true
126
+ }
127
+ ],
128
+ [
129
+ "typescript",
130
+ {
131
+ "project": "tsconfig.build.json"
132
+ }
133
+ ]
134
+ ]
135
+ },
136
+ "prettier": {
137
+ "quoteProps": "consistent",
138
+ "singleQuote": true,
139
+ "tabWidth": 2,
140
+ "trailingComma": "es5",
141
+ "useTabs": false
142
+ },
143
+ "jest": {
144
+ "preset": "@react-native/jest-preset",
145
+ "modulePathIgnorePatterns": [
146
+ "<rootDir>/example/node_modules",
147
+ "<rootDir>/lib/"
148
+ ]
149
+ },
150
+ "commitlint": {
151
+ "extends": [
152
+ "@commitlint/config-conventional"
153
+ ]
154
+ },
155
+ "release-it": {
156
+ "git": {
157
+ "commitMessage": "chore: release ${version}",
158
+ "tagName": "v${version}"
159
+ },
160
+ "npm": {
161
+ "publish": true
162
+ },
163
+ "github": {
164
+ "release": true
165
+ },
166
+ "plugins": {
167
+ "@release-it/conventional-changelog": {
168
+ "preset": {
169
+ "name": "angular"
170
+ }
171
+ }
172
+ }
173
+ },
174
+ "create-react-native-library": {
175
+ "type": "nitro-module",
176
+ "languages": "kotlin-swift",
177
+ "tools": [
178
+ "eslint",
179
+ "jest",
180
+ "lefthook",
181
+ "release-it"
182
+ ],
183
+ "version": "0.62.0"
184
+ }
185
+ }
@@ -0,0 +1,86 @@
1
+ import type { AnyMap, HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface JsonView extends HybridObject<{
4
+ ios: 'c++';
5
+ android: 'c++';
6
+ }> {
7
+ /**
8
+ * Returns the raw JSON string of the JSON view.
9
+ * @returns The raw JSON string of the JSON view.
10
+ */
11
+ rawJson(): string;
12
+ /**
13
+ * Returns the value of the key in the JSON view.
14
+ * @param key The key to get the value of. Must be a single key, not a path.
15
+ * @returns The value of the key in the JSON view.
16
+ */
17
+ getValue(key: string): JsonView | null;
18
+ /**
19
+ * Returns all the keys or fields of an object or array.
20
+ * Only for objects or arrays.
21
+ * @returns The keys of the JSON view.
22
+ */
23
+ keys(): string[];
24
+ /**
25
+ * Only for arrays. Returns the value of the index of an array.
26
+ * @param index The index to get the value from an array.
27
+ * @returns The value of the index in the array.
28
+ */
29
+ at(index: number): JsonView | null;
30
+ /**
31
+ * Returns all the values of the path specified.
32
+ * @param path simple path e.g $.key1.key2.key3. Indexing is not supported.
33
+ * @returns Returns a JsonView.
34
+ */
35
+ atPath(path: string /* $.key1.key2.key3 */): JsonView | null;
36
+ /**
37
+ * For dynamic retrieval of nested values with wildcards.
38
+ * Supports indexing with [*] or [number].
39
+ * @param path Must begin with $. e.g $.key1[*].key2[1]
40
+ * @returns all the values of the path specified.
41
+ */
42
+ atPathWithWildcard(path: string /* $.key1[*].key2[1] */): string[] | null;
43
+ /**
44
+ * Type of the value. e.g string, number, boolean, object, array.
45
+ */
46
+ type: string;
47
+ /**
48
+ * Only for objects or arrays.
49
+ * @returns The length of the value. 0 for other types.
50
+ */
51
+ length: number;
52
+ /**
53
+ * Returns the value as a string.
54
+ * @returns The value as a string.
55
+ */
56
+ asString(): string;
57
+ asNumber(): number;
58
+ asBoolean(): boolean;
59
+ /**
60
+ * For casting to JS objects or arrays.
61
+ * Only if element is an object or array.
62
+ * @returns `{data: Record<string, any> | any[]}`.
63
+ */
64
+ asObject(): AnyMap;
65
+ }
66
+
67
+ export interface FastJson extends HybridObject<{
68
+ ios: 'c++';
69
+ android: 'c++';
70
+ }> {
71
+ /**
72
+ * Parses a JSON string and returns a Promise that resolves to a JsonView.
73
+ * Not ideal, prefer parseFile or use simple JSON.parse if possible.
74
+ * @param str The JSON string.
75
+ * @returns A Promise that resolves to a JsonView or null. Response is not cached.
76
+ */
77
+ parseString(str: string): Promise<JsonView | null>;
78
+ /**
79
+ * Parses a JSON file and returns a Promise that resolves to a JsonView.
80
+ * No check is done if invalid path is provided. Error handling is left to the caller.
81
+ * @param path The path to the JSON file.
82
+ * @returns A Promise that resolves to a JsonView or null. Response is cached for future calls.
83
+ */
84
+ parseFile(path: string): Promise<JsonView | null>;
85
+ release(source: string): void;
86
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,6 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+
3
+ import type { FastJson, JsonView } from './FastJson.nitro';
4
+
5
+ export const fastJson = NitroModules.createHybridObject<FastJson>('FastJson');
6
+ export type { JsonView };