From f4f1ea657217724183119c9adbeabf181187f67c Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Tue, 30 Jun 2020 22:26:12 +0200 Subject: [PATCH] Add ramda --- .gitignore | 1 + dist/ffnm.min.js | 16 +++++++++------- package-lock.json | 11 +++++++++++ src/core.ts | 18 +++++++++++------- tsconfig.json | 9 +++++++++ 5 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 package-lock.json create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index c35f9d1..ecae11e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ test.html +node_modules/ diff --git a/dist/ffnm.min.js b/dist/ffnm.min.js index d960636..7a74cc9 100644 --- a/dist/ffnm.min.js +++ b/dist/ffnm.min.js @@ -12,13 +12,15 @@ var EVENTS; // FUNCTIONS //=== function validateSyntax() { - // Check every event - var eventsKeys = Object.keys(EVENTS).filter(function (key) { return !isNaN(Number(EVENTS[key])); }); - eventsKeys.forEach(function (event) { - var ddd = document.querySelector("[" + event + "]").length; - console.log(ddd); - }); - return true; + // Get every items from EVENTS + var eventsKeys = R.filter(function (key) { return !isNaN(Number(EVENTS[key])); }, Object.keys(EVENTS)); + // Check all event syntax + return eventsKeys.map(function (event) { + return R.map(function (element) { + console.log(element.getAttribute(event)); + return /^${event}/.test(element.getAttribute(event)); + }, document.querySelectorAll("[" + event + "]")).every(function (item) { return item; }); + }).every(function (event) { return event; }); } //=== // LINTER diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..56d903f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,11 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "@types/ramda": { + "version": "github:types/npm-ramda#9529aa3c8ff70ff84afcbc0be83443c00f30ea90", + "from": "github:types/npm-ramda#dist", + "dev": true + } + } +} diff --git a/src/core.ts b/src/core.ts index 68008e0..a3276e9 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,3 +1,4 @@ + //=== // VARIABLES //=== @@ -8,13 +9,16 @@ enum EVENTS {'i-click', 'i-scroll-up', 'i-scroll-down', 'i-hover'} //=== function validateSyntax(): boolean { - // Check every event - let eventsKeys = Object.keys(EVENTS).filter(key => !isNaN(Number(EVENTS[key]))); - eventsKeys.forEach((event) => { - let ddd = document.querySelector(`[${event}]`).length - console.log(ddd) - }) - return true + // Get every items from EVENTS + let eventsKeys: string[] = R.filter(key => !isNaN(Number(EVENTS[key])), Object.keys(EVENTS)); + + // Check all event syntax + return eventsKeys.map((event) => { + return R.map((element) => { + console.log(element.getAttribute(event)) + return /^${event}/.test(element.getAttribute(event)) + }, document.querySelectorAll(`[${event}]`)).every(item => item) + }).every(event => event) } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..7373e02 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "lib": [ + "es6", + "dom", + "dom.iterable" + ] + } +}