A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/jsonquerylang/jsonquery/commit/f252a598b6efc127a6104046f42587bdc7d73c65 below:

document function `substring` and change it into a standalone fu… · jsonquerylang/jsonquery@f252a59 · GitHub

File tree Expand file treeCollapse file tree 4 files changed

+45

-13

lines changed

Filter options

Expand file treeCollapse file tree 4 files changed

+45

-13

lines changed Original file line number Diff line number Diff line change

@@ -179,6 +179,10 @@ <h1>JSON Query</h1>

179 179

<a href="https://github.com/jsonquerylang/jsonquery/blob/main/reference/functions.md#split"

180 180

target="_blank"><code>split(text, separator)</code></a>

181 181

</li>

182 +

<li>

183 +

<a href="https://github.com/jsonquerylang/jsonquery/blob/main/reference/functions.md#substring"

184 +

target="_blank"><code>substring(text, start, end)</code></a>

185 +

</li>

182 186

<li>

183 187

<a href="https://github.com/jsonquerylang/jsonquery/blob/main/reference/functions.md#uniq"

184 188

target="_blank"><code>uniq()</code></a>

@@ -480,7 +484,7 @@ <h3 class="title">Debugger</h3>

480 484

</div>

481 485 482 486

<script type="module">

483 -

import { jsonquery, stringify, parse, compile } from 'https://cdn.jsdelivr.net/npm/@jsonquerylang/jsonquery@4/lib/jsonquery.js'

487 +

import { jsonquery, stringify, parse, compile } from '../lib/jsonquery.js'

484 488

import { Formatter, FracturedJsonOptions } from 'https://cdn.jsdelivr.net/npm/fracturedjsonjs/+esm'

485 489 486 490

window.jsonquery = { jsonquery, stringify, parse, compile }

Original file line number Diff line number Diff line change

@@ -531,6 +531,32 @@ jsonquery(data, 'split("a,b,c", ",")')

531 531

// ["a", "b", "c"]

532 532

```

533 533 534 +

## substring

535 + 536 +

Extract a substring from a string. When `end` is not provided, the length of the string will be used as `end`.

537 + 538 +

```text

539 +

substring(text, start)

540 +

substring(text, start, end)

541 +

```

542 + 543 +

Examples:

544 + 545 +

```js

546 +

const events = [

547 +

{"type": "start", "time": "2024-11-06 23:14:00" },

548 +

{"type": "initialize", "time": "2025-11-08 09:00:00" },

549 +

{"type": "end", "time": "2025-11-24 10:27:00" }

550 +

]

551 + 552 +

jsonquery(events, 'map(substring(.time, 0, 10))')

553 +

// [

554 +

// "2024-11-06",

555 +

// "2025-11-08",

556 +

// "2025-11-24"

557 +

// ]

558 +

```

559 + 534 560

## uniq

535 561 536 562

Create a copy of an array where all duplicates are removed.

Original file line number Diff line number Diff line change

@@ -210,7 +210,9 @@ export const functions: FunctionBuildersMap = {

210 210

separator !== undefined ? text.split(separator) : text.trim().split(/\s+/)

211 211

),

212 212 213 -

substring: (start: number, end: number) => (data: string) => data.slice(Math.max(start, 0), end),

213 +

substring: buildFunction((text: string, start: number, end?: number) =>

214 +

text.slice(Math.max(start, 0), end)

215 +

),

214 216 215 217

uniq:

216 218

() =>

Original file line number Diff line number Diff line change

@@ -543,42 +543,42 @@

543 543

"category": "substring",

544 544

"description": "should get a substring of a string with a start index",

545 545

"input": "123456",

546 -

"query": ["substring", 3],

546 +

"query": ["substring", ["get"], 3],

547 547

"output": "456"

548 548

},

549 549

{

550 550

"category": "substring",

551 551

"description": "should get a substring of a string with a start and end index",

552 -

"input": "123456",

553 -

"query": ["substring", 2, 4],

552 +

"input": { "value": "123456" },

553 +

"query": ["substring", ["get", "value"], 2, 4],

554 554

"output": "34"

555 555

},

556 556

{

557 557

"category": "substring",

558 558

"description": "should get a substring of a string with a start exceeding the string length",

559 -

"input": "123456",

560 -

"query": ["substring", 10],

559 +

"input": null,

560 +

"query": ["substring", "123456", 10],

561 561

"output": ""

562 562

},

563 563

{

564 564

"category": "substring",

565 565

"description": "should get a substring of a string with an end exceeding the string length",

566 -

"input": "123456",

567 -

"query": ["substring", 0, 10],

566 +

"input": null,

567 +

"query": ["substring", "123456", 0, 10],

568 568

"output": "123456"

569 569

},

570 570

{

571 571

"category": "substring",

572 572

"description": "should get a substring of a string with an end index smaller than the start index",

573 -

"input": "123456",

574 -

"query": ["substring", 3, 0],

573 +

"input": null,

574 +

"query": ["substring", "123456", 3, 0],

575 575

"output": ""

576 576

},

577 577

{

578 578

"category": "substring",

579 579

"description": "should get a substring of a string with a negative start index",

580 -

"input": "123456",

581 -

"query": ["substring", -2],

580 +

"input": null,

581 +

"query": ["substring", "123456", -2],

582 582

"output": "123456"

583 583

},

584 584

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4