Skip to content

Commit

Permalink
feature: redput: trim name
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Nov 2, 2023
1 parent 168b7f2 commit 5dac2ac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/parse-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// hello.js'.replace('//', '').trimStart()

export const parsePlugin = (raw) => {
const [comment, ...lines] = raw.split('\n');
const name = comment.replace('//', '').trimStart();

return {
name,
lines,
};
};
27 changes: 27 additions & 0 deletions lib/parse-plugin.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {test} from 'supertape';
import montag from 'montag';
import {parsePlugin} from './parse-plugin.js';

test('redput: parse-plugin', (t) => {
const {name} = parsePlugin(montag`
// hello.js
`);

const expected = 'hello.js';

t.equal(name, expected);
t.end();
});

test('redput: parse-plugin: lines', (t) => {
const {lines} = parsePlugin(montag`
// hello.js
export const report = () => 'hello';
`);

const expected = [`export const report = () => 'hello';`];

t.deepEqual(lines, expected);
t.end();
});

4 changes: 2 additions & 2 deletions lib/redput.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {getReport} from './get-report/get-report.js';
import {readGist} from './read-gist/read-gist.js';
import {writePlugin} from './write/index.js';
import {parseLink} from './parse-link.js';
import {parsePlugin} from './parse-plugin.js';

const SUCCESS = [null, 'Done'];

Expand All @@ -20,8 +21,7 @@ export const redput = async (link, {token}) => {
const raw = result.data.files['transform.js'].content;
const fixture = result.data.files['source.js'].content;

const [comment, ...lines] = raw.split('\n');
const name = comment.replace(/\/\/\s+?/, '');
const {name, lines} = parsePlugin(raw);

if (name.includes(':') || name.includes('{'))
return [
Expand Down

0 comments on commit 5dac2ac

Please sign in to comment.