@cdxoo/stringify-path-perlstyle

0.0.3 • Public • Published

@cdxoo/stringify-path-perlstyle

turns a path token array into a string; mostly for use in my own stuff

    var stringifyPath = require('@cdxoo/stringify-path-perlstyle');

    var examples = [
        [{ key: 'foo' }],
        
        [{ key: 'myobj',  type: 'object' }],
        [{ key: 'myobj',  type: 'object' }, { key: 'foo' }],

        [{ key: 'myary',  type: 'array' }],
        [
            { key: 'myary',  type: 'array' },
            { key: '0',  type: 'object' },
            { key: 'foo' }
        ],
        [{ key: 'myary',  type: 'array' }, { key: 'foo' }],

        [{ key: 'myfunc', type: 'function' }],

        // also we can indicate keys of json schema patternProperties
        [{ key: '[0-9]+', format: 'pattern' }],

    ];

    examples.map(stringifyPath);
    // or
    stringifyPath.all(examples);

    // =>
    //    $foo
    //
    //    %myobj
    //    %myobj -> $foo
    //
    //    @myary
    //    @myary -> %0 -> $foo
    //    @myary -> $foo
    //    
    //    &myfunc
    //
    //    $/[0-9]+/


    // indicateUntyped option
    stringifyPath.all([
        [{ key: 'myscalar', type: 'scalar' }]
        [{ key: 'myuntyped' }],
    ], { indicateUntyped: true });
    // => 
    //   $myscalar
    //   $<?>myuntyped

    // indicateScalarTypes option
    stringifyPath.all([
        [{ key: 'myobj', type: 'object'}, { key: 'name', type: 'string' }]
        [{ key: 'myuntyped' }],
    ], { indicateScalarTypes: true });
    // => 
    //   %myobj -> $<string>name
    //   $<?>myuntyped
    var { formatToken } = require('@cdxoo/stringify-path-perlstyle');

    formatToken({ key: 'myary', type: 'array' })
    // => @myary

Readme

Keywords

none

Package Sidebar

Install

npm i @cdxoo/stringify-path-perlstyle

Weekly Downloads

10

Version

0.0.3

License

MIT

Unpacked Size

4.84 kB

Total Files

4

Last publish

Collaborators

  • cdxoo