Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "ancient-cursor/src/lib/bundle"

Index

Type aliases

TBundlePath

TBundlePath: string

TBundlePaths

TBundlePaths: string | TBundlePathsStep[]

TBundlePathsStep

TBundlePathsStep: TBundlePath | TBundleSelector

TBundleSelector

TBundleSelector: any

Functions

get

  • Get value by paths in data.

    example
    
    import { get, TBundlePaths, } from 'ancient-cursor/lib/bundle';
    
    const paths:TBundlePaths = ['a', { b:2 }, 'c'];
    const path:TBundlePaths = 'a.1.c';
    const data = { a:[{ b:3, c:4 }, { b:2, c:5 }] };
    
    console.log (get (data, paths));
    // 5
    console.log (get (data, path));
    // 5
    

    Parameters

    Returns any

getByPath

  • getByPath(data: any, path: any): any
  • Based on lodash.get way to get value by current path in data.

    example
    
    import { getByPath, TBundlePaths, } from 'ancient-cursor/lib/bundle';
    
    const path:TBundlePaths =  'a.1.c';
    const data = { a:[{ b:3, c:4 }, { b:2, c:5 }] };
    
    console.log (getByPath (data, path));
    // 5
    

    Parameters

    • data: any
    • path: any

    Returns any

prepare

  • prepare(container: any, bundle: any): object
  • Get object with old value in current path.

    example
    
    import { prepare, TBundlePaths, IBundleValue, } from 'ancient-cursor/lib/bundle';
    
    const path:TBundlePaths = 'a.1.c';
    const bundle:IBundleValue = {
      path,
      value: 0,
      type: 'SomeType',
    };
    const container = { data: { a:[{ b:3, c:4 }, { b:2, c:5 }] } };
    
    console.log (prepare (container, bundle));
    // { bundlePath: ['a', '1', 'c']}
    

    Parameters

    • container: any
    • bundle: any

    Returns object

    • bundlePath: string[]

toPath

  • Try to transform paths to lodash.get path form.

    example
    
    import { toPath, TBundlePaths, } from 'ancient-cursor/lib/bundle';
    
    const paths:TBundlePaths =  ['a', { b:2 }];
    const data = { a:[{ b:3, c:4 }, { b:2, c:5 }] };
    
    console.log (toPath (data, paths));
    // a.1
    

    Parameters

    Returns TBundlePath

Object literals

Const bundleParsers

bundleParsers: object

extend

  • Extend data with object by path.

    example
    
    import { bundleParsers, get, TBundlePaths, IBundleValue, } from 'ancient-cursor/lib/bundle';
    
    const path:TBundlePaths = 'a.0.b';
    const bundle:IBundleValue = { type: 'extend', path, value: { d: 234 };
    const container = { data: { a: [{ b: { c: 123 } }] } };
    
    bundleParsers.extend (container, bundle, });
    
    console.log (get (container, path));
    // { c: 123, d: 234 }
    

    Parameters

    Returns object

    • bundle: IBundleValue
    • bundlePath: string[]
    • data: any
    • newValue: any

move

  • Move array element from start to end point by path in data.

    example
    
    import { bundleParsers, get, TBundlePaths, IBundleValue, } from 'ancient-cursor/lib/bundle';
    
    const path:TBundlePaths = ['x'];
    const bundle:IBundleValue = {
      type: 'move',
      path,
      from: 3,
      to: 5,
    }
    const container = { data: { x: [0,1,2,3,4,5,6] } };
    
    bundleParsers.push(container, bundle);
    
    console.log (get (container, path));
    // [0,1,2,4,5,3,6]
    

    Parameters

    Returns object

    • bundle: IBundleMove
    • bundlePath: string[]
    • data: any
    • newValue: any[]

push

  • Push new element to array by path in data.

    example
    
    import { bundleParsers, get, TBundlePaths, IBundleValue, } from 'ancient-cursor/lib/bundle';
    
    const path:TBundlePaths = ['x', ['y',2], 'a'];
    const bundle:IBundleValue = {
      type: 'push',
      path,
      value: [{ d: 567 }],
    };
    const container = { data: { x: [
      { y: 1, a: [{ b: { c: 123 } }, { b: { c: 456 } }] },
      { y: 2, a: [{ b: { c: 123 } }, { b: { c: 456 } }] },
    ] } };
    
    bundleParsers.push(container, bundle);
    
    console.log (get (container, path));
    // { y: 2, a: [{ b: { c: 123 } }, { b: { c: 456 } }, { d: 567 }] },
    

    Parameters

    Returns object

    • bundle: IBundleValue
    • bundlePath: string[]
    • data: any
    • newValue: any[]

remove

  • remove(container: object, bundle: IBundle): object
  • Remove all elements chosen by selector from array by path in data.

    example
    
    import { bundleParsers, get, TBundlePaths, IBundleValue, } from 'ancient-cursor/lib/bundle';
    
    const path:TBundlePaths = ['x', ['y',2], 'a'];
    const bundle:IBundleValue = {
      type: 'remove',
      path,
      selector: { b: { c: 123 } },
    };
    const container = { data: { x: [
      { y: 1, a: [{ b: { c: 123 } }, { b: { c: 456 } }] },
      { y: 2, a: [{ b: { c: 123 } }, { b: { c: 456 } }] },
    ] } };
    
    bundleParsers.remove(container, bundle);
    
    console.log (get (container, path));
    // { y: 2, a: [{ b: { c: 456 } }] }
    

    Parameters

    • container: object
      • data: any
    • bundle: IBundle

    Returns object

    • bundle: IBundle
    • bundlePath: string[]
    • data: any
    • newValue: any[]

set

  • Set value by path.

    example
    
    import { bundleParsers, get, TBundlePaths, IBundleValue, } from 'ancient-cursor/lib/bundle';
    
    const path:TBundlePaths = 'a.0.b.c';
    const bundle:IBundleValue = { type: 'set', path, value: 234, };
    const container = { data: { a: [{ b: { c: 123 } }] } };
    
    bundleParsers.set (container, bundle);
    
    console.log (get (container, path));
    // 234
    

    Parameters

    Returns object

    • bundle: IBundleValue
    • bundlePath: string[]
    • data: any
    • newValue: any

splice

  • Incapsulate array of something into array by path in data.

    example
    
    import { bundleParsers, get, TBundlePaths, IBundleValue, } from 'ancient-cursor/lib/bundle';
    
    const path:TBundlePaths = 'a';
    const bundle:IBundleValue = {
      type: 'splice',
      path,
      start: 1,
      deleteCount: 0,
      values: [
        { b: { c: 234 } },
        { b: { c: 345 } },
      ],
    };
    const container = { data: { a: [{ b: { c: 123 } }] } };
    
    bundleParsers.splice(container, bundle);
    
    console.log (get (container, path));
    [
      { b: { c: 123 } },
      { b: { c: 234 } },
      { b: { c: 345 } },
      { b: { c: 456 } },
    ]
    
    

    Parameters

    Returns object

    • bundle: IBundleSplice
    • bundlePath: string[]
    • data: any
    • newValue: any[]

unset

  • unset(container: object, bundle: IBundle): object
  • Unset data by path.

    example
    
    import { bundleParsers, get, TBundlePaths, IBundleValue, } from 'ancient-cursor/lib/bundle';
    
    const path:TBundlePaths = 'a.0.b.c';
    const bundle:IBundleValue = { type: 'unset', path, };
    const container = { data: { a: [{ b: { c: 123 } }] } };
    
    bundleParsers.unset (container, bundle);
    
    console.log (get (container, 'a.0.b'));
    // { }
    

    Parameters

    • container: object
      • data: any
    • bundle: IBundle

    Returns object

    • bundle: IBundle
    • bundlePath: string[]
    • data: any
    • newValue: any

Generated using TypeDoc