Generalize camera make/model text formatting
This commit is contained in:
parent
2673c0dbb0
commit
1a154e71bd
@ -5,9 +5,10 @@ const APPLE_01 : Camera = { make: 'Apple', model: 'iPhone 11' };
|
|||||||
const APPLE_02 : Camera = { make: 'Apple', model: 'iPhone 15 Pro Max' };
|
const APPLE_02 : Camera = { make: 'Apple', model: 'iPhone 15 Pro Max' };
|
||||||
const FUJIFILM : Camera = { make: 'Fujifilm', model: 'X-T5' };
|
const FUJIFILM : Camera = { make: 'Fujifilm', model: 'X-T5' };
|
||||||
const CANON : Camera = { make: 'Canon', model: 'Canon EOS 800D' };
|
const CANON : Camera = { make: 'Canon', model: 'Canon EOS 800D' };
|
||||||
const NIKON : Camera = {
|
const NIKON : Camera = { make: 'Nikon Corporation', model: 'Nikon D7000' };
|
||||||
make: 'Nikon Corporation',
|
const RICOH : Camera = {
|
||||||
model: 'Nikon D7000',
|
make: 'RICOH IMAGING COMPANY, LTD.',
|
||||||
|
model: 'RICOH GR III',
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('Camera', () => {
|
describe('Camera', () => {
|
||||||
@ -19,6 +20,7 @@ describe('Camera', () => {
|
|||||||
expect(formatCameraText(FUJIFILM)).toBe('Fujifilm X-T5');
|
expect(formatCameraText(FUJIFILM)).toBe('Fujifilm X-T5');
|
||||||
expect(formatCameraText(CANON)).toBe('Canon EOS 800D');
|
expect(formatCameraText(CANON)).toBe('Canon EOS 800D');
|
||||||
expect(formatCameraText(NIKON)).toBe('Nikon D7000');
|
expect(formatCameraText(NIKON)).toBe('Nikon D7000');
|
||||||
|
expect(formatCameraText(RICOH)).toBe('RICOH GR III');
|
||||||
});
|
});
|
||||||
it('labels models correctly', () => {
|
it('labels models correctly', () => {
|
||||||
expect(formatCameraText(APPLE, 'never')).toBe('iPhone 11 Pro');
|
expect(formatCameraText(APPLE, 'never')).toBe('iPhone 11 Pro');
|
||||||
|
|||||||
@ -56,14 +56,17 @@ export const cameraFromPhoto = (
|
|||||||
: fallback ?? CAMERA_PLACEHOLDER;
|
: fallback ?? CAMERA_PLACEHOLDER;
|
||||||
|
|
||||||
export const formatCameraText = (
|
export const formatCameraText = (
|
||||||
{ make: makeRaw, model: modelRaw }: Camera,
|
{ make, model: modelRaw }: Camera,
|
||||||
includeMake: 'always' | 'never' | 'if-not-apple' = 'if-not-apple',
|
includeMake: 'always' | 'never' | 'if-not-apple' = 'if-not-apple',
|
||||||
removeIPhoneOnLongModels?: boolean,
|
removeIPhoneOnLongModels?: boolean,
|
||||||
) => {
|
) => {
|
||||||
// Remove 'Corporation' from makes like 'Nikon Corporation'
|
// Capture simple make without modifiers like 'Corporation' or 'Company'
|
||||||
const make = makeRaw.replace(/ Corporation/i, '');
|
const makeSimple = make.match(/^(\S+)/)?.[1];
|
||||||
// Remove potential duplicate make from model
|
const doesModelStartWithMake = (
|
||||||
let model = modelRaw.replace(`${make} `, '');
|
makeSimple &&
|
||||||
|
modelRaw.toLocaleLowerCase().startsWith(makeSimple.toLocaleLowerCase())
|
||||||
|
);
|
||||||
|
let model = modelRaw;
|
||||||
if (
|
if (
|
||||||
removeIPhoneOnLongModels &&
|
removeIPhoneOnLongModels &&
|
||||||
model.includes('iPhone') &&
|
model.includes('iPhone') &&
|
||||||
@ -73,7 +76,8 @@ export const formatCameraText = (
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
includeMake === 'never' ||
|
includeMake === 'never' ||
|
||||||
includeMake === 'if-not-apple' && make === 'Apple'
|
doesModelStartWithMake ||
|
||||||
|
(includeMake === 'if-not-apple' && make === 'Apple')
|
||||||
) ? model
|
) ? model
|
||||||
: `${make} ${model}`;
|
: `${make} ${model}`;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user