Skip to content

Commit

Permalink
fix: remove final - from addlistener slug (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Oct 12, 2021
1 parent a0ab0f4 commit 9eb327b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ export function formatMethodSignature(m: DocsInterfaceMethod) {
return `${m.name}(${m.parameters.length > 0 ? '...' : ''})`;
}

export function formatMethodSignatureForSlug(m: DocsInterfaceMethod) {
if (m.name === 'addListener' && m.parameters.length > 0) {
return `addListener(${m.parameters[0].type.replace(/\"/g, `'`)})`;
}
return `${m.name}(${m.parameters.length > 0 ? '...' : ''})`;
}

function linkToken(data: DocsData, token: string) {
const t = token.replace(/`/g, '');
const i = data.interfaces.find(i => {
Expand Down
4 changes: 2 additions & 2 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
} from './types';
import { getTsProgram } from './transpile';
import GithubSlugger from 'github-slugger';
import { formatMethodSignature } from './formatting';
import { formatMethodSignatureForSlug } from './formatting';

/**
* Given either a tsconfig file path, or exact input files, will
Expand Down Expand Up @@ -325,7 +325,7 @@ function getInterfaceMethod(
slug: '',
};

m.slug = slugify(formatMethodSignature(m));
m.slug = slugify(formatMethodSignatureForSlug(m));

return m;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Below is an index of all the methods available.
* [`impact(...)`](#impact)
* [`notification(...)`](#notification)
* [`vibrate(...)`](#vibrate)
* [`addListener('vibrate', ...)`](#addlistenervibrate-)
* [`addListener('vibrate', ...)`](#addlistenervibrate)
* [`removeAllListeners()`](#removealllisteners)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
Expand Down
2 changes: 1 addition & 1 deletion src/test/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"complexTypes": [
"VibrateListener"
],
"slug": "addlistenervibrate-"
"slug": "addlistenervibrate"
},
{
"name": "removeAllListeners",
Expand Down
2 changes: 1 addition & 1 deletion src/test/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('parse', () => {

const m3 = api.methods[3];
expect(m3.name).toBe(`addListener`);
expect(m3.slug).toBe(`addlistenervibrate-`);
expect(m3.slug).toBe(`addlistenervibrate`);
expect(m3.docs).toBe(`Add a listener. Callback has VibrateOptions.`);
expect(m3.signature).toBe(
`(eventName: 'vibrate', listenerFunc: VibrateListener) => Promise<void>`,
Expand Down

0 comments on commit 9eb327b

Please sign in to comment.