From 7bf52d6fa305a376568185b2ef2bdefb7dcc9b58 Mon Sep 17 00:00:00 2001 From: Eder Sampaio Date: Sun, 25 Sep 2022 18:36:38 -0300 Subject: [PATCH] Add rollup.js (#10) * [FEAT] add .eslintignore * [FEAT] update .eslintrc.json * [FEAT] update .gitignore * [FEAT] update babel config * [FEAT] update travis config * [FEAT] add .prettierrc * [CHORE] remove dead code * [FEAT] add jest config * [CHORE] remove dead code * [FEAT] implement VanillaScrollspy class * [FEAT] add unit tests * [FEAT] add HTML mock * [FEAT] add sample HTML * [CHORE] update file * [FEAT] add rollup config * [FEAT] add .npmignore * [CHORE] remove dead code * [CHORE] remove dead code * [CHORE] remove dead code --- .eslintignore | 2 + .eslintrc.json | 18 +- .gitignore | 72 +- .npmignore | 14 + .prettierrc | 5 + .travis.yml | 2 +- README.md | 134 +- babel.config.cjs | 3 + babel.config.js | 5 - dist/vanillajs-scrollspy.js | 229 - dist/vanillajs-scrollspy.js.map | 1 - dist/vanillajs-scrollspy.min.js | 3 +- dist/vanillajs-scrollspy.min.js.map | 1 - index.js | 1 - jest.config.cjs | 9 + lib/index.js | 132 - package-lock.json | 7806 +++++++---------- package.json | 75 +- {examples => public}/index.html | 4 +- rollup.config.js | 21 + src/VanillaScrollspy/VanillaScrollspy.spec.js | 96 + src/VanillaScrollspy/index.js | 85 + src/index.js | 95 - src/utils/htmlMock.js | 63 + tests/index.spec.js | 57 - webpack.config.babel.js | 21 - 26 files changed, 3559 insertions(+), 5395 deletions(-) create mode 100644 .eslintignore create mode 100644 .npmignore create mode 100644 .prettierrc create mode 100644 babel.config.cjs delete mode 100644 babel.config.js delete mode 100644 dist/vanillajs-scrollspy.js delete mode 100644 dist/vanillajs-scrollspy.js.map delete mode 100644 dist/vanillajs-scrollspy.min.js.map delete mode 100644 index.js create mode 100644 jest.config.cjs delete mode 100644 lib/index.js rename {examples => public}/index.html (95%) create mode 100644 rollup.config.js create mode 100644 src/VanillaScrollspy/VanillaScrollspy.spec.js create mode 100644 src/VanillaScrollspy/index.js delete mode 100644 src/index.js create mode 100644 src/utils/htmlMock.js delete mode 100644 tests/index.spec.js delete mode 100644 webpack.config.babel.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..29f4434 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +coverage +dist diff --git a/.eslintrc.json b/.eslintrc.json index 5e8313f..7d23f4a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,13 +1,17 @@ { - "extends": "airbnb-base", - "plugins": [ - "import" - ], "env": { "browser": true, - "node": true + "es2021": true, + "node": true, + "jest": true + }, + "extends": ["eslint:recommended", "plugin:prettier/recommended"], + "overrides": [ + ], + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" }, - "globals": { - "document": false + "rules": { } } diff --git a/.gitignore b/.gitignore index 1bb729a..bb10ce0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,58 +4,24 @@ logs npm-debug.log* yarn-debug.log* yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul +# jest coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Typescript v1 declaration files -typings/ - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env - -.DS_Store -.vscode diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..96bac92 --- /dev/null +++ b/.npmignore @@ -0,0 +1,14 @@ +public +src +.editorconfig +.eslintignore +.eslintrc.json +.gitignore +.prettierrc +.travis.yml +CONTRIBUTING.md +LICENSE.md +README.md +babel.config.cjs +jest.config.cjs +rollup.config.js diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..0e5c1db --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "trailingComma": "none", + "semi": false, + "singleQuote": true +} diff --git a/.travis.yml b/.travis.yml index fa6a035..fb5e403 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ cache: "node_modules" before_script: - - npm run build:all + - npm run build after_success: - npm run coveralls diff --git a/README.md b/README.md index d77ff0e..c0c07c9 100644 --- a/README.md +++ b/README.md @@ -4,72 +4,63 @@ ScrollSpy in pure JavaScript. -## Browser Support - -![IE](https://cloud.githubusercontent.com/assets/398893/3528325/20373e76-078e-11e4-8e3a-1cb86cf506f0.png) | ![Chrome](https://cloud.githubusercontent.com/assets/398893/3528328/23bc7bc4-078e-11e4-8752-ba2809bf5cce.png) | ![Firefox](https://cloud.githubusercontent.com/assets/398893/3528329/26283ab0-078e-11e4-84d4-db2cf1009953.png) | ![Opera](https://cloud.githubusercontent.com/assets/398893/3528330/27ec9fa8-078e-11e4-95cb-709fd11dac16.png) | ![Safari](https://cloud.githubusercontent.com/assets/398893/3528331/29df8618-078e-11e4-8e3e-ed8ac738693f.png) ---- | --- | --- | --- | --- -IE 10+ ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ - ## Installation -```bash +```bash $ npm install vanillajs-scrollspy --save ``` ## How to use ```javascript -const scrollspy = VanillaScrollspy(menu, speed, easing); -scrollspy.init(); +const menu = document.querySelector('#navbar') +const scrollspy = VanillaScrollspy({ menu }) +scrollspy.init() ``` - **menu:** menu selector (#id, .class, ...) - **speed (optional):** scroll speed, default value `2000` -- **easing (optional):** scroll type `'easeOutSine'`, `'easeInOutSine'` or `'easeInOutQuint'`, default value `'easeInOutQuint'` +- **easing (optional):** scroll type `'easeOutSine'`, `'easeInOutSine'` or `'easeInOutQuint'`, default value `'easeOutSine'` ### ES6 ```javascript -import VanillaScrollspy from 'vanillajs-scrollspy'; +import VanillaScrollspy from 'vanillajs-scrollspy' -const navbar = document.querySelector('#navbar'); -const scrollspy = VanillaScrollspy(navbar); -scrollspy.init(); +const menu = document.querySelector('#navbar') +const scrollspy = VanillaScrollspy({ menu }) +scrollspy.init() ``` ### CommonJS ```javascript -const VanillaScrollspy = require('vanillajs-scrollspy').default; +const VanillaScrollspy = require('vanillajs-scrollspy').default -const navbar = document.querySelector('#navbar'); -const scrollspy = VanillaScrollspy(navbar); -scrollspy.init(); +const menu = document.querySelector('#navbar') +const scrollspy = VanillaScrollspy({ menu }) +scrollspy.init() ``` ### UMD in Browser ```html - - - - ``` After that the library will be available to the Global as `VanillaScrollspy`. Follow an example: ``` javascript -const navbar = document.querySelector('#navbar'); -const scrollspy = VanillaScrollspy(navbar); -scrollspy.init(); +const menu = document.querySelector('#navbar') +const scrollspy = VanillaScrollspy({ menu }) +scrollspy.init() ``` ## Examples ### Basic template -Available in [`examples/index.html`](examples/index.html). +Available in [`public/index.html`](public/index.html). ``` html @@ -78,86 +69,67 @@ Available in [`examples/index.html`](examples/index.html). VanillaJS ScrollSpy - -