Improve pixel lens formatting
This commit is contained in:
parent
c564621e91
commit
b6a5a0c5da
@ -17,6 +17,7 @@ describe('Lens', () => {
|
||||
describe('correctly formats', () => {
|
||||
it('iPhone lenses', () => {
|
||||
expect(formatLensText(IPHONE_15_PRO_FRONT)).toBe('15 Pro front');
|
||||
expect(formatLensText(IPHONE_15_PRO_FRONT, 'long')).toBe('Apple iPhone 15 Pro front TrueDepth camera 2.69mm f/1.9');
|
||||
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)');
|
||||
@ -25,10 +26,10 @@ describe('Lens', () => {
|
||||
expect(formatLensText(IPHONE_12_PRO_MAX_BACK_TELEPHOTO_NO_MAKE)).toBe('12 Pro Max Main (5.1mm)');
|
||||
});
|
||||
it('Pixel lenses', () => {
|
||||
expect(formatLensText(PIXEL_8_PRO_BACK, 'medium')).toBe('Pixel 8 Pro Back Camera (6.9mm)');
|
||||
expect(formatLensText(PIXEL_8_PRO_BACK_NO_MAKE, 'medium')).toBe('Pixel 8 Pro Back Camera (6.9mm)');
|
||||
expect(formatLensText(PIXEL_8_PRO_BACK, 'medium')).toBe('Pixel 8 Pro Back (6.9mm)');
|
||||
expect(formatLensText(PIXEL_8_PRO_BACK_NO_MAKE, 'medium')).toBe('Pixel 8 Pro Back (6.9mm)');
|
||||
expect(formatLensText(PIXEL_8_PRO_BACK, 'short')).toBe('Back Camera (6.9mm)');
|
||||
expect(formatLensText(PIXEL_6A_BACK, 'medium')).toBe('Pixel 6a Back Camera (2.35mm)');
|
||||
expect(formatLensText(PIXEL_6A_BACK, 'medium')).toBe('Pixel 6a Back (2.35mm)');
|
||||
expect(formatLensText(PIXEL_6A_BACK, 'short')).toBe('Back Camera (2.35mm)');
|
||||
});
|
||||
});
|
||||
|
||||
@ -105,21 +105,18 @@ export const formatLensText = (
|
||||
);
|
||||
|
||||
const model = isLensApple(lens)
|
||||
? formatAppleLensText(modelRaw, length === 'medium')
|
||||
? formatAppleLensText(modelRaw, length !== 'short')
|
||||
: isLensGoogle(lens)
|
||||
? formatGoogleLensText(modelRaw, length === 'medium')
|
||||
? formatGoogleLensText(modelRaw, length !== 'short')
|
||||
: doesModelStartWithMake
|
||||
? modelRaw.replace(makeSimple, '').trim()
|
||||
: modelRaw;
|
||||
|
||||
switch (length) {
|
||||
case 'long':
|
||||
return make ? `${make} ${model}` : model;
|
||||
return make ? `${make} ${modelRaw}` : modelRaw;
|
||||
case 'medium':
|
||||
return doesModelStartWithMake
|
||||
? model.replace(makeSimple, '').trim()
|
||||
: model;
|
||||
case 'short':
|
||||
return doesModelStartWithMake
|
||||
? model.replace(makeSimple, '').trim()
|
||||
: model;
|
||||
return model;
|
||||
}
|
||||
};
|
||||
|
||||
@ -18,7 +18,7 @@ export const isLensApple = ({ make, model }: Lens) =>
|
||||
|
||||
export const formatAppleLensText = (
|
||||
model: string,
|
||||
includePhoneName?: boolean,
|
||||
includeDeviceName?: boolean,
|
||||
) => {
|
||||
const [
|
||||
_,
|
||||
@ -31,11 +31,11 @@ export const formatAppleLensText = (
|
||||
|
||||
const format = (lensName: string, includeFocalLength = true) => {
|
||||
let result = '';
|
||||
if (includePhoneName) {
|
||||
if (includeDeviceName) {
|
||||
result += `${phoneName} `;
|
||||
}
|
||||
result += lensName;
|
||||
if (!includePhoneName) {
|
||||
if (!includeDeviceName) {
|
||||
result += ' Camera';
|
||||
}
|
||||
if (includeFocalLength && focalLength) {
|
||||
|
||||
@ -19,22 +19,28 @@ export const isLensGoogle = ({ make, model }: Lens) =>
|
||||
|
||||
export const formatGoogleLensText = (
|
||||
model: string,
|
||||
includePhoneName?: boolean,
|
||||
includeDeviceName?: boolean,
|
||||
) => {
|
||||
const [
|
||||
_,
|
||||
_match,
|
||||
phoneName,
|
||||
lensVariant,
|
||||
lensVariant, // Expected: 'Back' or 'Front'
|
||||
lensVariantRemainder, // Expected: 'Camera'
|
||||
focalLength,
|
||||
_aperture,
|
||||
// eslint-disable-next-line max-len
|
||||
] = (/^(Pixel (?:[0-9a-z])+(?: Pro)*) (.+) ([0-9\.]+)mm.*?f\/([0-9\.]+)/gi.exec(model) ?? []);
|
||||
] = (/^(Pixel (?:[0-9a-z])+(?: Pro)*)(?: (back|front))* (.+) ([0-9\.]+)mm.*?f\/([0-9\.]+)/gi.exec(model) ?? []);
|
||||
|
||||
if (phoneName && lensVariant && focalLength) {
|
||||
const lensName = `${capitalizeWords(lensVariant)} (${focalLength}mm)`;
|
||||
return includePhoneName
|
||||
? `${phoneName} ${lensName}`
|
||||
: lensName;
|
||||
const lensName = capitalizeWords(lensVariant);
|
||||
const focalText = `(${focalLength}mm)`;
|
||||
if (includeDeviceName) {
|
||||
return `${phoneName} ${lensName} ${focalText}`;
|
||||
} else {
|
||||
return lensVariantRemainder
|
||||
? `${lensName} ${capitalizeWords(lensVariantRemainder)} ${focalText}`
|
||||
: `${lensName} ${focalText}`;
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user