@cdxoo/stringify-path-perlstyle
v0.0.3
Published
turns a path token array into a perl-ish string
Downloads
93
Readme
@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