Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lethargy-ts

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lethargy-ts - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6-beta.0

lib/codes.d.ts

68

lib/index.js

@@ -1,10 +0,11 @@

'use strict';
/** Converts default WheelEvent to our custom IWheelEvent */
const getWheelEvent = (e) => ({
deltaX: e.deltaX,
deltaY: e.deltaY,
deltaZ: e.deltaZ,
timeStamp: e.timeStamp,
});
const getWheelEvent = (e) => {
const event = "nativeEvent" in e ? e.nativeEvent : e;
return {
deltaX: event.deltaX || 0,
deltaY: event.deltaY || 0,
deltaZ: event.deltaZ || 0,
timeStamp: event.timeStamp,
};
};
/** Returns array of deltas of the wheel event */

@@ -48,3 +49,3 @@ const getDeltas = (e) => [e.deltaX, e.deltaY, e.deltaZ];

exports.CHECK_RESULT_CODES = void 0;
var CHECK_RESULT_CODES;
(function (CHECK_RESULT_CODES) {

@@ -60,5 +61,15 @@ CHECK_RESULT_CODES["ALL_OTHER_CHECKS_FAILED"] = "ALL_OTHER_CHECKS_FAILED";

CHECK_RESULT_CODES["ANOMALY_INERTIA_JUMP"] = "ANOMALY_INERTIA_JUMP";
})(exports.CHECK_RESULT_CODES || (exports.CHECK_RESULT_CODES = {}));
})(CHECK_RESULT_CODES || (CHECK_RESULT_CODES = {}));
class Lethargy {
/** The wheelDelta threshold. If an event has a wheelDelta below this value, it will not register */
sensitivity;
/** Threshold for the amount of time between wheel events for them to be deemed separate */
delay;
/** Max percentage decay speed of an Inertia event */
inertiaDecay;
/** `[lastKnownHumanEvent, ...inertiaEvents]` */
previousEvents;
/** Deltas above this are considered high velocity */
highVelocity;
constructor({ sensitivity = 2, inertiaDecay = 20, delay = 100, highVelocity = 100, } = {}) {

@@ -75,7 +86,6 @@ this.sensitivity = Math.max(1, sensitivity);

check(e) {
var _a;
const isEvent = e instanceof Event;
// No event provided
if (!isEvent)
throw new Error("No event provided");
const isValidEvent = ("nativeEvent" in e ? e.nativeEvent : e) instanceof Event;
// Not a valid event
if (!isValidEvent)
throw new Error(`"${e}" is not a valid event`);
const event = getWheelEvent(e);

@@ -92,3 +102,3 @@ // DeltaModule is too small

// Don't push event to the previousEvents if it's timestamp is less than last seen event's timestamp
else if (event.timeStamp > (((_a = this.previousEvents.at(-1)) === null || _a === void 0 ? void 0 : _a.timeStamp) || 0)) {
else if (event.timeStamp > (this.previousEvents.at(-1)?.timeStamp || 0)) {
this.previousEvents.push(event);

@@ -105,3 +115,3 @@ }

isHuman: true,
reason: exports.CHECK_RESULT_CODES.NO_PREVIOUS_EVENT_TO_COMPARE,
reason: CHECK_RESULT_CODES.NO_PREVIOUS_EVENT_TO_COMPARE,
};

@@ -114,3 +124,3 @@ }

isHuman: true,
reason: exports.CHECK_RESULT_CODES.PAST_TIMESTAMP_EVENT,
reason: CHECK_RESULT_CODES.PAST_TIMESTAMP_EVENT,
};

@@ -122,3 +132,3 @@ }

isHuman: true,
reason: exports.CHECK_RESULT_CODES.ENOUGH_TIME_PASSED,
reason: CHECK_RESULT_CODES.ENOUGH_TIME_PASSED,
};

@@ -132,3 +142,3 @@ }

isHuman: true,
reason: exports.CHECK_RESULT_CODES.DELTA_MODULE_IS_BIGGER,
reason: CHECK_RESULT_CODES.DELTA_MODULE_IS_BIGGER,
};

@@ -140,3 +150,3 @@ }

isHuman: true,
reason: exports.CHECK_RESULT_CODES.VECTORS_DONT_MATCH,
reason: CHECK_RESULT_CODES.VECTORS_DONT_MATCH,
};

@@ -149,3 +159,3 @@ }

isHuman: true,
reason: exports.CHECK_RESULT_CODES.HIGH_VELOCITY_NON_DECREASING_DELTAS,
reason: CHECK_RESULT_CODES.HIGH_VELOCITY_NON_DECREASING_DELTAS,
};

@@ -159,3 +169,3 @@ }

isHuman: true,
reason: exports.CHECK_RESULT_CODES.NON_DECREASING_DELTAS_OF_KNOWN_HUMAN,
reason: CHECK_RESULT_CODES.NON_DECREASING_DELTAS_OF_KNOWN_HUMAN,
};

@@ -167,3 +177,3 @@ }

isHuman: true,
reason: exports.CHECK_RESULT_CODES.ANOMALY_INERTIA_JUMP,
reason: CHECK_RESULT_CODES.ANOMALY_INERTIA_JUMP,
};

@@ -174,3 +184,3 @@ }

isHuman: false,
reason: exports.CHECK_RESULT_CODES.ALL_OTHER_CHECKS_FAILED,
reason: CHECK_RESULT_CODES.ALL_OTHER_CHECKS_FAILED,
};

@@ -180,9 +190,3 @@ }

exports.Lethargy = Lethargy;
exports.compareVectors = compareVectors;
exports.getBiggestDeltaModule = getBiggestDeltaModule;
exports.getDeltas = getDeltas;
exports.getSign = getSign;
exports.getWheelEvent = getWheelEvent;
exports.isAnomalyInertia = isAnomalyInertia;
export { CHECK_RESULT_CODES, Lethargy, compareVectors, getBiggestDeltaModule, getDeltas, getSign, getWheelEvent, isAnomalyInertia };
//# sourceMappingURL=index.js.map
{
"name": "lethargy-ts",
"version": "0.0.5",
"version": "0.0.6-beta.0",
"description": "Distinguish between scroll events initiated by the user, and those by inertial scrolling",

@@ -17,5 +17,5 @@ "repository": "https://github.com/snelsi/lethargy-ts",

],
"main": "lib/index.js",
"module": "lib/index.esm.js",
"types": "lib/types/index.d.ts",
"type": "module",
"exports": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [

@@ -27,5 +27,4 @@ "lib"

"prettier": "prettier --write .",
"lint": "eslint",
"lint-fix": "eslint --fix",
"fix": "npm run prettier && npm run lint-fix",
"lint": "eslint --fix",
"fix": "npm run prettier && npm run lint",
"test": "vitest",

@@ -37,17 +36,17 @@ "coverage": "vitest run --coverage",

"devDependencies": {
"@rollup/plugin-typescript": "^11.0.0",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"@vitest/coverage-c8": "^0.29.3",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.7.0",
"happy-dom": "^8.9.0",
"husky": "^8.0.3",
"lint-staged": "^13.2.0",
"prettier": "^2.8.5",
"pretty-quick": "^3.1.3",
"rollup": "^3.20.0",
"typescript": "^5.0.2",
"vite": "^4.2.0",
"vitest": "^0.29.3"
"@rollup/plugin-typescript": "^11.1.6",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@vitest/coverage-v8": "^1.6.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"happy-dom": "^14.7.1",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"pretty-quick": "^4.0.0",
"rollup": "^4.17.2",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vitest": "^1.6.0"
},

@@ -54,0 +53,0 @@ "lint-staged": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc