Skip to content

Commit

Permalink
feat: add isIwaFile util
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Feb 21, 2023
1 parent 8e35da6 commit dcf7014
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './get-message-proto';
export * from './is-iwa-file';
9 changes: 9 additions & 0 deletions src/utils/is-iwa-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const IWA_FILE_DIRECTORY = 'Index/';
const IWA_FILE_EXTENSION = '.iwa';

/**
* Check if a file is an iwa file
*/
export const isIwaFile = (relativeFilePath: string): boolean =>
relativeFilePath.startsWith(IWA_FILE_DIRECTORY) &&
relativeFilePath.endsWith(IWA_FILE_EXTENSION);
15 changes: 15 additions & 0 deletions tests/utils/is-iwa-file.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest';
import { isIwaFile } from '../../src';

const testCases: [string, boolean][] = [
['Index/foo.iwa', true],
['Index/foo.jpg', false],
['Metadata/foo.iwa', false],
];

describe('isIwaFile', () => {
testCases.forEach(([relativeFilePath, expected]) =>
it(`${relativeFilePath} -> ${expected}`, () =>
expect(isIwaFile(relativeFilePath)).toBe(expected)),
);
});

0 comments on commit dcf7014

Please sign in to comment.