1
0
mirror of https://github.com/uetchy/namae.git synced 2025-08-20 18:08:11 +09:00

style: prettier

This commit is contained in:
2020-08-31 08:41:53 +09:00
committed by uetchy
parent 9278b7a2ee
commit f5f7b51fcb
73 changed files with 1014 additions and 5220 deletions

View File

@@ -1,32 +1,32 @@
import { send, sendError, fetch } from '../../../util/http'
import { NowRequest, NowResponse } from '@vercel/node'
import { send, sendError, fetch } from '../../../util/http';
import { NowRequest, NowResponse } from '@vercel/node';
const APPLICATION_ID = process.env.NTA_APPLICATION_ID
const APPLICATION_ID = process.env.NTA_APPLICATION_ID;
export default async function handler(
req: NowRequest,
res: NowResponse
): Promise<void> {
const { query } = req.query
const { query } = req.query;
if (!query || typeof query !== 'string') {
return sendError(res, new Error('No query given'))
return sendError(res, new Error('No query given'));
}
const encodedQuery = encodeURIComponent(
query.replace(/[A-Za-z0-9]/g, (str) =>
String.fromCharCode(str.charCodeAt(0) + 0xfee0)
)
)
);
try {
const response = await fetch(
`https://api.houjin-bangou.nta.go.jp/4/name?id=${APPLICATION_ID}&name=${encodedQuery}&mode=1&target=1&type=02`,
'GET'
)
const body: string[] = (await response.text()).split('\n').slice(0, -1)
);
const body: string[] = (await response.text()).split('\n').slice(0, -1);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const header = body.shift()!.split(',')
const header = body.shift()!.split(',');
const result = body.map((csv) => {
const entry = csv.split(',').map((item) =>
item
@@ -36,7 +36,7 @@ export default async function handler(
)
// eslint-disable-next-line no-irregular-whitespace
.replace(/ /g, ' ')
)
);
return {
index: entry[0],
@@ -73,8 +73,8 @@ export default async function handler(
excluded: entry[29],
processSection: entry[2],
modifiedSection: entry[3],
}
})
};
});
send(res, {
meta: {
@@ -91,8 +91,8 @@ export default async function handler(
englishName: entry.englishName,
}))
.slice(10) || [],
})
});
} catch (err) {
sendError(res, err)
sendError(res, err);
}
}