fix: use string endsWith to filter by extension (#3097)
This commit is contained in:
parent
92108431f0
commit
6a13a85e26
@ -1,4 +1,9 @@
|
|||||||
import { parseLinkHeader, getAllResponses, getPathDepth } from '../backendUtil';
|
import {
|
||||||
|
parseLinkHeader,
|
||||||
|
getAllResponses,
|
||||||
|
getPathDepth,
|
||||||
|
filterByPropExtension,
|
||||||
|
} from '../backendUtil';
|
||||||
import { oneLine } from 'common-tags';
|
import { oneLine } from 'common-tags';
|
||||||
import nock from 'nock';
|
import nock from 'nock';
|
||||||
|
|
||||||
@ -79,3 +84,14 @@ describe('getPathDepth', () => {
|
|||||||
expect(getPathDepth('{{year}}/{{slug}}')).toBe(2);
|
expect(getPathDepth('{{year}}/{{slug}}')).toBe(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('filterByPropExtension', () => {
|
||||||
|
it('should return filtered array based on extension', () => {
|
||||||
|
expect(
|
||||||
|
filterByPropExtension('.html.md', 'path')([{ path: 'file.html.md' }, { path: 'file.json' }]),
|
||||||
|
).toEqual([{ path: 'file.html.md' }]);
|
||||||
|
expect(
|
||||||
|
filterByPropExtension('html.md', 'path')([{ path: 'file.html.md' }, { path: 'file.json' }]),
|
||||||
|
).toEqual([{ path: 'file.html.md' }]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
import { flow, fromPairs, get } from 'lodash';
|
import { flow, fromPairs, get } from 'lodash';
|
||||||
import { map } from 'lodash/fp';
|
import { map } from 'lodash/fp';
|
||||||
import { fromJS } from 'immutable';
|
import { fromJS } from 'immutable';
|
||||||
import { fileExtension } from './path';
|
|
||||||
import unsentRequest from './unsentRequest';
|
import unsentRequest from './unsentRequest';
|
||||||
import APIError from './APIError';
|
import APIError from './APIError';
|
||||||
|
|
||||||
type Formatter = (res: Response) => Promise<string | Blob | unknown>;
|
type Formatter = (res: Response) => Promise<string | Blob | unknown>;
|
||||||
|
|
||||||
export const filterByPropExtension = (extension: string, propName: string) => <T>(arr: T[]) =>
|
export const filterByPropExtension = (extension: string, propName: string) => <T>(arr: T[]) =>
|
||||||
arr.filter(el => fileExtension(get(el, propName)) === extension);
|
arr.filter(el =>
|
||||||
|
get(el, propName, '').endsWith(extension.startsWith('.') ? extension : `.${extension}`),
|
||||||
|
);
|
||||||
|
|
||||||
const catchFormatErrors = (format: string, formatter: Formatter) => (res: Response) => {
|
const catchFormatErrors = (format: string, formatter: Formatter) => (res: Response) => {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user