@oklinov/google-maps-data-ast
v0.0.17
Published
Parse and/or stringify Google Maps proprietary data type (aka !1m3 style)
Downloads
1,196
Maintainers
Readme
Parse and/or stringify Google Maps proprietary data type (aka !1m3 style)
npm i google-maps-data-ast
/ yarn add google-maps-data-ast
Get started
import { parse, stringify } from 'google-maps-data-ast';
const data = '!3m1!4b1!4m5!3m4!1s0x0:0xe665b3308d32f379!8m2!3d-37.8805676!4d145.1644849';
const ast = parse(data);
Abstract syntax tree for !3m1!4b1!4m5!3m4!1s0x0:0xe665b3308d32f379!8m2!3d-37.8805676!4d145.1644849
:
[
{
id: 3,
code: 'm',
type: 'matrix',
value: '1',
data: 1,
children: [ { id: 4, code: 'b', type: 'boolean', value: '1', data: true } ]
},
{
id: 4,
code: 'm',
type: 'matrix',
value: '5',
data: 5,
children: [
{
id: 3,
code: 'm',
type: 'matrix',
value: '4',
data: 4,
children: [
{
id: 1,
code: 's',
type: 'string',
value: '0x0:0xe665b3308d32f379',
data: [ 0, 16601872622479930000 ]
},
{
id: 8,
code: 'm',
type: 'matrix',
value: '2',
data: 2,
children: [
{
id: 3,
code: 'd',
type: 'double',
value: '-37.8805676',
data: -37.8805676
},
{
id: 4,
code: 'd',
type: 'double',
value: '145.1644849',
data: 145.1644849
}
]
}
]
}
]
}
]
const modifiedData = stringify([
{
code: 'b',
type: 'boolean',
value: '0',
id: 1,
},
...ast
])
// is now equivalent to
const modifiedData = '!1b0!3m1!4b1!4m5!3m4!1s0x0:0xe665b3308d32f379!8m2!3d-37.8805676!4d145.1644849'