-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[![Maven Central](https://img.shields.io/maven-central/v/org.jetbrains.kotlin-wrappers/kotlin-prantlf-jsonlint)](https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-prantlf-jsonlint) | ||
|
||
# Module kotlin-prantlf-jsonlint | ||
|
||
Kotlin wrapper for the [JSON Lint](https://prantlf.github.io/jsonlint/) library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
`kotlin-library-conventions` | ||
} | ||
|
||
dependencies { | ||
jsMainApi(projects.kotlinJs) | ||
jsMainApi(npm(libs.npm.prantlf.jsonlint)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
description=Kotlin wrapper for JSON Lint | ||
js.platform=web |
19 changes: 19 additions & 0 deletions
19
kotlin-prantlf-jsonlint/src/jsMain/kotlin/prantlf/jsonlint/ParseMode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package prantlf.jsonlint | ||
|
||
import seskar.js.JsValue | ||
|
||
/** | ||
* JSON parsing modes, which are a shortcut for setting multiple parsing options. | ||
*/ | ||
sealed external interface ParseMode { | ||
companion object { | ||
@JsValue("json") | ||
val json: ParseMode | ||
|
||
@JsValue("cjson") | ||
val cjson: ParseMode | ||
|
||
@JsValue("json5") | ||
val json5: ParseMode | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
kotlin-prantlf-jsonlint/src/jsMain/kotlin/prantlf/jsonlint/ParseOptions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package prantlf.jsonlint | ||
|
||
import js.objects.JsPlainObject | ||
|
||
/** | ||
* Options to customize JSON input parsing. | ||
*/ | ||
@JsPlainObject | ||
external interface ParseOptions { | ||
/** | ||
* Ignore the leading BOM in the JSON input, if it is detected. | ||
* | ||
* The default is `false`, which will cause the parser to fail, when a BOM is encountered. | ||
*/ | ||
val ignoreBOM: Boolean? | ||
|
||
/** | ||
* Ignore comments in the JSON input (CJSON, JSON5). | ||
* | ||
* The default is `false`, which will cause the parser to fail, when a comment is encountered. | ||
*/ | ||
val ignoreComments: Boolean? | ||
|
||
/** | ||
* Ignore trailing commas after the last item in objects and arrays in the JSON input (JSON5). | ||
* | ||
* The default is `false`, which will cause the parser to fail, when a trailing comma is encountered. | ||
*/ | ||
val ignoreTrailingCommas: Boolean? | ||
|
||
/** | ||
* Allow quotes around strings to be single quotes (JSON5). | ||
* | ||
* The default is `false`, which will cause the parser to fail, when a single quote around a string is encountered. | ||
*/ | ||
val allowSingleQuotedStrings: Boolean? | ||
|
||
/** | ||
* Allow or disallow duplicated keys in objects. | ||
* | ||
* The default is `true`, which will allow duplicate keys to occur and return only the last occurrence in the parsed output. | ||
*/ | ||
val allowDuplicateObjectKeys: Boolean? | ||
|
||
/** | ||
* Set the JSON parsing mode as a shortcut for setting multiple parsing options. | ||
* | ||
* Available values: `'json' | 'cjson' | 'json5'` | ||
*/ | ||
val mode: ParseMode? | ||
|
||
/** | ||
* Transform the value, which was parsed for a particular object key from the JSON input. | ||
* | ||
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter. | ||
*/ | ||
val reviver: Reviver? | ||
} |
12 changes: 12 additions & 0 deletions
12
kotlin-prantlf-jsonlint/src/jsMain/kotlin/prantlf/jsonlint/Reviver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package prantlf.jsonlint | ||
|
||
/** | ||
* Can transform the value, which was parsed for a particular object key from the JSON input. | ||
* | ||
* See the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter). | ||
* | ||
* @param key - a property name | ||
* @param vaslue - a property value | ||
* @returns the value to be set in the parsed JSON object | ||
*/ | ||
typealias Reviver = (key: String, value: Any?) -> Any? |
62 changes: 62 additions & 0 deletions
62
kotlin-prantlf-jsonlint/src/jsMain/kotlin/prantlf/jsonlint/parse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@file:JsModule("@prantlf/jsonlint") | ||
|
||
package prantlf.jsonlint | ||
|
||
import js.objects.ReadonlyRecord | ||
|
||
/** | ||
* Parses a string formatted as JSON to a JSON output (primitive type, object | ||
* or array). It is compatible with the native `JSON.parse` method. | ||
* | ||
* @example | ||
* ```ts | ||
* import { parse } from '@prantlf/jsonlint' | ||
* const parsed = parse('string with JSON data') | ||
* ``` | ||
* | ||
* @param input - a string input to parse | ||
* @param reviverOrOptions - either a value reviver or an object | ||
* with multiple options | ||
* @returns the parsed result - a primitive value, array or object | ||
*/ | ||
external fun parse(input: String): ReadonlyRecord<String, Any?> | ||
|
||
/** | ||
* Parses a string formatted as JSON to a JSON output (primitive type, object | ||
* or array). It is compatible with the native `JSON.parse` method. | ||
* | ||
* @example | ||
* ```ts | ||
* import { parse } from '@prantlf/jsonlint' | ||
* const parsed = parse('string with JSON data') | ||
* ``` | ||
* | ||
* @param input - a string input to parse | ||
* @param reviverOrOptions - either a value reviver or an object | ||
* with multiple options | ||
* @returns the parsed result - a primitive value, array or object | ||
*/ | ||
external fun parse( | ||
input: String, | ||
reviver: Reviver = definedExternally, | ||
): ReadonlyRecord<String, Any?> | ||
|
||
/** | ||
* Parses a string formatted as JSON to a JSON output (primitive type, object | ||
* or array). It is compatible with the native `JSON.parse` method. | ||
* | ||
* @example | ||
* ```ts | ||
* import { parse } from '@prantlf/jsonlint' | ||
* const parsed = parse('string with JSON data') | ||
* ``` | ||
* | ||
* @param input - a string input to parse | ||
* @param reviverOrOptions - either a value reviver or an object | ||
* with multiple options | ||
* @returns the parsed result - a primitive value, array or object | ||
*/ | ||
external fun parse( | ||
input: String, | ||
options: ParseOptions = definedExternally, | ||
): ReadonlyRecord<String, Any?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters