Skip to content

Commit

Permalink
Add wrappers for JSON Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Jan 20, 2025
1 parent f47e00a commit 5a98625
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ To learn more please refer to the [API Reference](https://jetbrains.github.io/ko
| `kotlin-node` | [API](https://jetbrains.github.io/kotlin-wrappers/kotlin-node) | [README](kotlin-node/README.md) | | [![Maven Central](https://img.shields.io/maven-central/v/org.jetbrains.kotlin-wrappers/kotlin-node)](https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-node/) |
| `kotlin-null-writable` | [API](https://jetbrains.github.io/kotlin-wrappers/kotlin-null-writable) | [README](kotlin-null-writable/README.md) | | [![Maven Central](https://img.shields.io/maven-central/v/org.jetbrains.kotlin-wrappers/kotlin-null-writable)](https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-null-writable/) |
| `kotlin-popperjs-core` | [API](https://jetbrains.github.io/kotlin-wrappers/kotlin-popperjs-core) | [README](kotlin-popperjs-core/README.md) | | [![Maven Central](https://img.shields.io/maven-central/v/org.jetbrains.kotlin-wrappers/kotlin-popperjs-core)](https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-popperjs-core/) |
| `kotlin-prantlf-jsonlint` | [API](https://jetbrains.github.io/kotlin-wrappers/kotlin-prantlf-jsonlint) | [README](kotlin-prantlf-jsonlint/README.md) | | [![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/) |
| `kotlin-preact-signals-core` | [API](https://jetbrains.github.io/kotlin-wrappers/kotlin-preact-signals-core) | [README](kotlin-preact-signals-core/README.md) | | [![Maven Central](https://img.shields.io/maven-central/v/org.jetbrains.kotlin-wrappers/kotlin-preact-signals-core)](https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-preact-signals-core/) |
| `kotlin-preact-signals-react` | [API](https://jetbrains.github.io/kotlin-wrappers/kotlin-preact-signals-react) | [README](kotlin-preact-signals-react/README.md) | | [![Maven Central](https://img.shields.io/maven-central/v/org.jetbrains.kotlin-wrappers/kotlin-preact-signals-react)](https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-preact-signals-react/) |
| `kotlin-react` | [API](https://jetbrains.github.io/kotlin-wrappers/kotlin-react) | [README](kotlin-react/README.md) | | [![Maven Central](https://img.shields.io/maven-central/v/org.jetbrains.kotlin-wrappers/kotlin-react)](https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-react/) |
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ null-writable.npm.version=^2.0.1
# https://www.npmjs.com/package/@popperjs/core
popperjs-core.npm.version=^2.11.8

# https://www.npmjs.com/package/@prantlf/jsonlint
prantlf-jsonlint.npm.version=^16.0.0

# https://www.npmjs.com/package/@preact/signals-core
preact-signals-core.npm.version=^1.8.0

Expand Down
5 changes: 5 additions & 0 deletions kotlin-prantlf-jsonlint/README.md
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.
8 changes: 8 additions & 0 deletions kotlin-prantlf-jsonlint/build.gradle.kts
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))
}
2 changes: 2 additions & 0 deletions kotlin-prantlf-jsonlint/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
description=Kotlin wrapper for JSON Lint
js.platform=web
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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package prantlf.jsonlint

import js.json.Reviver
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?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@file:JsModule("@prantlf/jsonlint")

package prantlf.jsonlint

import js.json.Reviver
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?>
3 changes: 3 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ include("kotlin-null-writable")
// Kotlin/JS: Popper Core wrappers
include("kotlin-popperjs-core")

// Kotlin/JS: JSON Lint wrappers
include("kotlin-prantlf-jsonlint")

// Kotlin/JS: Preact Signals Core wrappers
include("kotlin-preact-signals-core")

Expand Down

0 comments on commit 5a98625

Please sign in to comment.