Skip to content

Commit

Permalink
refactor: make hasMoreThanNColors a top level function
Browse files Browse the repository at this point in the history
  • Loading branch information
tams sokari committed Nov 1, 2023
1 parent 6caa86d commit ca36a34
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions packages/components/smart-camera-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -1185,18 +1185,16 @@ class PoweredBySmileId extends HTMLElement {
}
}

class SmileIdCanvas {
static hasMoreThanNColors(data, n = 16) {
const colors = new Set();
for (let i = 0; i < Math.min(data.length, 10000); i += 4) {
// eslint-disable-next-line no-bitwise
colors.add((data[i] << 16) | (data[i + 1] << 8) | data[i + 2]);
if (colors.size > n) {
return true;
}
}
return false;
}
function hasMoreThanNColors(data, n = 16) {
const colors = new Set();

Check failure on line 1189 in packages/components/smart-camera-web.js

View workflow job for this annotation

GitHub Actions / components

Unexpected tab character

Check failure on line 1189 in packages/components/smart-camera-web.js

View workflow job for this annotation

GitHub Actions / components

Expected indentation of 2 spaces but found 1 tab
for (let i = 0; i < Math.min(data.length, 10000); i += 4) {

Check failure on line 1190 in packages/components/smart-camera-web.js

View workflow job for this annotation

GitHub Actions / components

Unexpected tab character

Check failure on line 1190 in packages/components/smart-camera-web.js

View workflow job for this annotation

GitHub Actions / components

Expected indentation of 2 spaces but found 1 tab
// eslint-disable-next-line no-bitwise

Check failure on line 1191 in packages/components/smart-camera-web.js

View workflow job for this annotation

GitHub Actions / components

Unexpected tab character

Check failure on line 1191 in packages/components/smart-camera-web.js

View workflow job for this annotation

GitHub Actions / components

Expected indentation of 4 spaces but found 2 tabs
colors.add((data[i] << 16) | (data[i + 1] << 8) | data[i + 2]);

Check failure on line 1192 in packages/components/smart-camera-web.js

View workflow job for this annotation

GitHub Actions / components

Unexpected tab character

Check failure on line 1192 in packages/components/smart-camera-web.js

View workflow job for this annotation

GitHub Actions / components

Expected indentation of 4 spaces but found 2 tabs
if (colors.size > n) {

Check failure on line 1193 in packages/components/smart-camera-web.js

View workflow job for this annotation

GitHub Actions / components

Unexpected tab character

Check failure on line 1193 in packages/components/smart-camera-web.js

View workflow job for this annotation

GitHub Actions / components

Expected indentation of 4 spaces but found 2 tabs
return true;
}
}
return false;
}

window.customElements.define('powered-by-smile-id', PoweredBySmileId);
Expand Down Expand Up @@ -1600,9 +1598,9 @@ class SmartCameraWeb extends HTMLElement {
if (!disableImageTests) {
const imageData = context.getImageData(0, 0, canvas.width, canvas.height);

const hasManyColors = SmileIdCanvas.hasMoreThanNColors(imageData.data);
const hasEnoughColors = hasMoreThanNColors(imageData.data);

if (hasManyColors) {
if (hasEnoughColors) {
return context;
}
this.selectSelfie.disabled = true;
Expand Down

0 comments on commit ca36a34

Please sign in to comment.