dotsy
v0.1.1
Published
Display randomly positioned, non-overlapping, customized dots in your HTML.
Downloads
38
Maintainers
Readme
Dotsy
Dotsy is a JavaScript library with which you can create HTML for randomly positioned, non-overlapping, customized dots. You can set:
- the height and width of the container
- the radius and color of each dot
Then Dotsy calculates the locations and creates the HTML for you.
This library can be used, for example, in software that may focus on:
- subitizing
- counting
- arithmetic
How to use this library
For a working example to play with online, see symbolinker.github.io/dotsy. The source code of the example can be found in the docs folder of the repository.
How to add it to your project? There are various ways:
Using a <script>
element
There is no need to download or install anything. Your website just needs to have a <script>
element that results in getting one of the following files from jsDelivr:
- dotsy.es2020-esm.js
- dotsy.es2017-esm.js
- dotsy.es2015-iife.js
esYEAR: those are JavaScript language versions. esm: the ECMAScript module is simply the best choice: easy, safe, future proof. iife: an immediately invoked function expression for browsers that do not support ESM.
For each of those ".js" files there is a minified version (".min.js") - a smaller file (of only 17 kB) with the same capabilities.
A <script>
element using the recommended "dotsy.es2017-esm.min.js":
<script type="module">
import * as dotsy from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/dotsy.es2017-esm.min.js';
let settings = new dotsy.Settings();
// ...(set settings here)...
let html = dotsy.getHtml(settings);
// ...(get your HTML element)...
yourElement.innerHTML = html;
</script>
A <script>
element using the with-older-browsers-compatible "dotsy.es2015-iife.min.js":
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dotsy.es2015-iife.min.js"></script>
<script type="text/javascript">
window.addEventListener('DOMContentLoaded', (event) => {
let settings = new dotsy.Settings();
// ...(set settings here)...
let html = dotsy.getHtml(settings);
// ...(get your HTML element)...
yourElement.innerHTML = html;
});
</script>
Using npm
This library has been published to npm. After opening a folder in VS Code, run in the terminal:
npm i dotsy
Verify that dotsy
has been added to the node_modules
folder. Then you can choose:
Using the CommonJS module (the .cjs
file) in myFile.js
:
const dotsy = require('dotsy');
const settings = new dotsy.Settings();
Using the ESM module (the .mjs
file) in myFile.js
or myFile.ts
:
import * as dotsy from 'dotsy';
const settings = new dotsy.Settings();
How to use this repo
Follow these steps to set up (and verify) a development environment for this repository:
- Install Node.js, Git and VS Code.
- Fork (or clone), checkout and then open the root folder of this repository in VS Code.
- Open the VS Code Terminal and run:
npm ci
This loads all the devDependencies from the tree as specified in package-lock.json. - Compiling the library:
All of the following commands run some script as defined in package.json:
npm run strictcheck
to do type checking, to check whether a successful compilation is possible.npm run clean
to run eslint (performing auto-fixes).npm test
to run all unit tests from the 'tests' folder.npm run build
creates a single-file library in different formats and language versions in the 'dist' folder. Note: the 'src' folder contains all the source code files. - Testing localhost:
For testing localhost with live reload from VS Code, you could install the VS Code extension Five Server. Then open '/localhost/index.html' in VS Code and click
> Go Live
in the bottom right corner of VS Code. The browser starts up automatically.
License
The Dotsy repository uses the most permissive licensing available. The "BSD Zero Clause License" (0BSD) allows for commercial + non-commercial use, closed + open source, with + without modifications, etc. and is equivalent to licenses like:
The "BSD Zero Clause License" (0BSD) does not have the condition
(...), provided that the above copyright notice and this permission notice appear in all copies.
which is part of the "MIT License" (MIT) and its shorter equivalent "ISC License" (ISC). Apart from that they are all equivalent.
Ask or contribute
- ask questions about anything that is not clear or when you'd like help.
- share ideas or what you've made.
- report a bug.
- request an enhancement.
- open a pull request. (The command
npm run clean
runs eslint.)