@platyplus/rx-jmespath
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

RxJS JMESPath package

Adaptation of the official Javascript JMESPath package to work along with RxJS.

Passes all the original compliance tests.

Installation

yarn add @platyplus/rx-jmespath

Usage

search$ operator

function search$(
  expression: string | Observable<string>,
  options: SearchOptions
): (data$: Observable<any>) => Observable<any>

Example:

import { search$ } from '@platyplus/rx-jmespath'
import { of } from 'rxjs'

of({ a: { b: { c: 'hello' } } })
  .pipe(search$('a.b.c'))
  .subscribe((result) => {
    console.log(result) // <- returns 'hello'
  })

search

Exact same function as in the official package:

search(obj: any, expression: string ) => any

Options

type SearchOptions<T = CustomOptions> = T & {
  getField?: FieldGetter<T>
  getIdentity?: IdentityGetter<T>
  circularData?: boolean
}

Field getter

const getField: FieldGetter<T = Record<string,unknown>> = (
  obj: any,
  property: string | number,
  options: SearchOptions<T>
): Observable<any> => {
  return of(obj[key] ?? null)
}

Identity getter

const getIdentity: IdentityGetter<T = Record<string,unknown>> = (
  obj: any,
  options: SearchOptions<T>
): Observable<any> => {
  return of(obj)
}

Circular data

Sometimes, objects are mutually referenced, so browsing them entirely would create an infinite loop. You can prevent this in setting this option to `true.

When true, the expression * expression raises an error instead of making the processing fail.

The circularData option defaults to false.

Readme

Keywords

none

Package Sidebar

Install

npm i @platyplus/rx-jmespath

Weekly Downloads

1

Version

0.0.1

License

none

Unpacked Size

24.1 kB

Total Files

14

Last publish

Collaborators

  • plmercereau