Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Turn lines into array #329

Open
jschuur opened this issue Apr 7, 2022 · 1 comment
Open

Feature Request: Turn lines into array #329

jschuur opened this issue Apr 7, 2022 · 1 comment

Comments

@jschuur
Copy link

jschuur commented Apr 7, 2022

Turing a block of text into an array where each line is an element would be useful.

I currently use https://arraythis.com/ for that.

@jschuur
Copy link
Author

jschuur commented Apr 9, 2022

I ended up throwing together a little custom script to do this:

function main(state) {
  const lines = state.text.split('\n');

  const output = lines
    .filter(line => line.trim() !== '')
    .map((line) => `  ${(Number.isNaN(Number.parseFloat(line)) ? `'${line}'` : Number.parseFloat(line))}`)
    .join(',\n');

  state.fullText = `[\n${output}\n]`;
  state.postInfo(`${lines.length} array items converted`);
}

This also checks if something is a string or a number and preserves the type too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant