Skip to content

Instantly share code, notes, and snippets.

@josephg
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephg/bd05e9dd240dc0ac7888 to your computer and use it in GitHub Desktop.
Save josephg/bd05e9dd240dc0ac7888 to your computer and use it in GitHub Desktop.

New components:

  • (i) insert (was di:)

  • (d) drop

  • (dn) drop if null

  • (r) remove (was p:null)

  • (p) pick up

  • (e) edit

Worked examples

insert z:6:

old {o:{z:{di:6}}}
size: 20

new ['z',{i:6}]
size: 13

rename doc.x -> doc.z

old {o:{x:{p:0},z:{d:0}}}
size: 31

new [['x',{p:0}],['z',{d:0}]]
size: 29

Move x into the list between 'happy' and 'apple' given {x:5, y:['happy', 'apple']}

old {o:{x:{p:0}, y:{l:{1:{d:0}}}}}
size: 43

new [['x',{p:0}],['y',1,{d:0}]]
size: 31

given {x:{y:5}}, capitalize x and y:

{o: {
    x: {p: 0, o: {y: {p: 1}}},
    X: {d: 0, o: {Y: {d: 1}}}
}}
size: 67

[
  ['x',[{p:0},['y',{p:1}]]],
  ['X',[{d:0},['Y',{d:1}]]]
]
size: 61

Convert the document {x:10,y:20,z:30} to an array [10,20,30]:

{ o: { x: { p: 0 }, y: { p: 1 }, z: { p: 2 } },
  p: null,
  di: [],
  l: { '0': { d: 0 }, '1': { d: 1 }, '2': { d: 2 } } }
size: 102


[
  {r:{},i:[]},
  ['x',{p:0}],['y',{p:1}],['z',{p:2}],
  [0,{d:0}],[1,{d:1}],[2,{d:2}]
]
size: 95

Rewrite the document {x:{y:{secret:"data"}}} as {y:{x:{secret:"data"}}}:

{ o: 
   { x: { p: null, o: { y: { p: 0 } } },
     y: { di: { x: {} }, o: { x: { d: 0 } } } } }
size: 78

[
  ['x',[{r:{}}, ['y', {p:0}]]],
  ['y',[{i:{}}, ['x', {d:0}]]]
]
size: 63

insert something deep in an object (at user.details.name.first):

old: {o:{user:{o:{details:{o:{name:{o:{first:{i:"Seph"}}}}}}}}}
size: 76

new: ['user', 'details', 'name', 'first', {i:"Seph"}]
size: 46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment