Object into Array
Convert object into a list of tuples representing the field and the value.
Before
const palette = {
apricot: "#f47868",
lightning: "#ffcd1c",
delta: "6f44f0",
};
After
const palette = [
["apricot", "#f47868"],
["lightning", "#ffcd1c"],
["delta", "6f44f0"],
];
Preview
Command
jmr{[mi[s:<enter>
r,t,;vgsms[lems"
- Go to the line below with
j
, this is because we need to be inside of the object for the next step. mr{[
replaces the nearest pair of curly braces "{" with square brackets "["mi[
selects inside the entire array- Use
s
to enter select mode, which searches inside our selection and creates sub-selections based on a pattern - Input
:
and then hit<enter>
, which will place a cursor on every ":" creating many single-width selections r,
replaces each selection with a ",". Essentially we've replaced each colon with a commat,
moves the cursor on each line to the ending comma;
collapses the selection around each cursor into a single selectionvgs
selects each line excluding the final commams[
surrounds each individual selection with "[" to turn it into an array. We're almost done here. We just need to transform the first item in each sub-array into a string.l
moves 1 character forward, replacing the selection with just a 1-width selectione
selects until the end of each word. Since we start at the first character and select until the end, this selects the entire word.ms"
surrounds each word with double quotes to make strings