Offer abbreviated formatting for Pixel lenses
This commit is contained in:
parent
c94fb65ee1
commit
075f104367
@ -6,11 +6,19 @@ const IPHONE_15_PRO_BACK_WIDE: Lens = { make: 'Apple', model: 'iPhone 15 Pro bac
|
||||
const IPHONE_15_PRO_BACK_MAIN: Lens = { make: 'Apple', model: 'iPhone 15 Pro back triple camera 6.765mm f/1.78' };
|
||||
const IPHONE_15_PRO_BACK_TELEPHOTO: Lens = { make: 'Apple', model: 'iPhone 15 Pro back triple camera 6.765mm f/2.8' };
|
||||
|
||||
const PIXEL_8_PRO_BACK: Lens = { make: 'Google', model: 'Pixel 8 Pro back camera 6.9mm f/1.68' };
|
||||
|
||||
describe('Lens', () => {
|
||||
it('correctly formats iPhone lenses', () => {
|
||||
expect(formatLensText(IPHONE_15_PRO_FRONT)).toBe('15 Pro front');
|
||||
expect(formatLensText(IPHONE_15_PRO_BACK_WIDE)).toBe('15 Pro Wide (6.765mm)');
|
||||
expect(formatLensText(IPHONE_15_PRO_BACK_MAIN)).toBe('15 Pro Main (6.765mm)');
|
||||
expect(formatLensText(IPHONE_15_PRO_BACK_TELEPHOTO)).toBe('15 Pro Telephoto (6.765mm)');
|
||||
describe('correctly formats', () => {
|
||||
it('iPhone lenses', () => {
|
||||
expect(formatLensText(IPHONE_15_PRO_FRONT)).toBe('15 Pro front');
|
||||
expect(formatLensText(IPHONE_15_PRO_BACK_WIDE)).toBe('15 Pro Wide (6.765mm)');
|
||||
expect(formatLensText(IPHONE_15_PRO_BACK_MAIN)).toBe('15 Pro Main (6.765mm)');
|
||||
expect(formatLensText(IPHONE_15_PRO_BACK_TELEPHOTO)).toBe('15 Pro Telephoto (6.765mm)');
|
||||
});
|
||||
it('Pixel lenses', () => {
|
||||
expect(formatLensText(PIXEL_8_PRO_BACK, 'medium')).toBe('Pixel 8 Pro Back Camera (6.9mm)');
|
||||
expect(formatLensText(PIXEL_8_PRO_BACK, 'short')).toBe('Back Camera (6.9mm)');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -2,6 +2,7 @@ import { Photo } from '@/photo';
|
||||
import { parameterize } from '@/utility/string';
|
||||
import { formatAppleLensText, isLensMakeApple } from '../platforms/apple';
|
||||
import { MISSING_FIELD } from '@/app/paths';
|
||||
import { formatGoogleLensText, isLensMakeGoogle } from '../platforms/google';
|
||||
|
||||
const LENS_PLACEHOLDER: Lens = { make: 'Lens', model: 'Model' };
|
||||
|
||||
@ -103,7 +104,9 @@ export const formatLensText = (
|
||||
|
||||
const model = isLensMakeApple(make)
|
||||
? formatAppleLensText(modelRaw, length === 'medium')
|
||||
: modelRaw;
|
||||
: isLensMakeGoogle(make)
|
||||
? formatGoogleLensText(modelRaw, length === 'medium')
|
||||
: modelRaw;
|
||||
|
||||
switch (length) {
|
||||
case 'long':
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
/* eslint-disable max-len */
|
||||
import { Camera } from '@/camera';
|
||||
import { Lens } from '../lens';
|
||||
|
||||
@ -26,6 +25,7 @@ export const formatAppleLensText = (
|
||||
side,
|
||||
focalLength,
|
||||
aperture,
|
||||
// eslint-disable-next-line max-len
|
||||
] = (/iPhone ([0-9a-z]{1,3}(?: (?:Pro|Max|Plus))*).*?(back|front).*?([0-9\.]+)mm.*?f\/([0-9\.]+)/gi.exec(model) ?? []);
|
||||
|
||||
const format = (lensName: string, includeFocalLength = true) => {
|
||||
|
||||
40
src/platforms/google.ts
Normal file
40
src/platforms/google.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { Camera } from '@/camera';
|
||||
import { Lens } from '../lens';
|
||||
import { capitalizeWords } from '@/utility/string';
|
||||
|
||||
const MAKE_GOOGLE = 'google';
|
||||
|
||||
export const isCameraMakeGoogle = (make?: string) =>
|
||||
make?.toLocaleLowerCase() === MAKE_GOOGLE;
|
||||
|
||||
export const isCameraGoogle = ({ make }: Camera) =>
|
||||
isCameraMakeGoogle(make);
|
||||
|
||||
export const isLensMakeGoogle = (make?: string) =>
|
||||
make?.toLocaleLowerCase() === MAKE_GOOGLE;
|
||||
|
||||
export const isLensGoogle = ({ make }: Lens) =>
|
||||
isLensMakeGoogle(make);
|
||||
|
||||
export const formatGoogleLensText = (
|
||||
model: string,
|
||||
includePhoneName?: boolean,
|
||||
) => {
|
||||
const [
|
||||
_,
|
||||
phoneName,
|
||||
lensVariant,
|
||||
focalLength,
|
||||
_aperture,
|
||||
// eslint-disable-next-line max-len
|
||||
] = (/^(Pixel (?:[0-9])+(?: Pro)*) (.+) ([0-9\.]+)mm.*?f\/([0-9\.]+)/gi.exec(model) ?? []);
|
||||
|
||||
if (phoneName && lensVariant && focalLength) {
|
||||
const lensName = `${capitalizeWords(lensVariant)} (${focalLength}mm)`;
|
||||
return includePhoneName
|
||||
? `${phoneName} ${lensName}`
|
||||
: lensName;
|
||||
}
|
||||
|
||||
return model;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user