Skip to content

Commit

Permalink
Fix typos and improve language in docs and code
Browse files Browse the repository at this point in the history
  • Loading branch information
undergroundwires committed Dec 28, 2024
1 parent 530187d commit 1a4ec74
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish

on:
release:
types: [created] # will be triggered when a NON-draft release is created and published.
types: [created] # It will be triggered when a NON-draft release is created and published.

jobs:

Expand All @@ -11,8 +11,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: master # otherwise it defaults to the version tag missing bump commit
fetch-depth: 0 # fetch all history
ref: master # Otherwise it defaults to the version tag missing bump commit
fetch-depth: 0 # Fetch all history
- uses: actions/setup-node@v4
with:
node-version: 22.x
Expand Down Expand Up @@ -51,8 +51,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: master # otherwise it defaults to the version tag missing bump commit
fetch-depth: 0 # fetch all history
ref: master # Otherwise it defaults to the version tag missing bump commit
fetch-depth: 0 # Fetch all history
- name: Checkout to bump commit
run: git checkout "$(git rev-list "${{ github.event.release.tag_name }}"..master | tail -1)"
- run: |
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ez-consent

> 🍪 Minimal & vanilla JS only cookie consent banner with no dependencies.
> 🍪 A minimal, vanilla JavaScript cookie consent banner with no dependencies.
[![](https://img.shields.io/npm/v/ez-consent)](https://www.npmjs.com/package/ez-consent)
[![](https://data.jsdelivr.com/v1/package/npm/ez-consent/badge?style=rounded)](https://www.jsdelivr.com/package/npm/ez-consent)
Expand All @@ -15,7 +15,7 @@
- Vanilla JavaScript only ✔️
- It does not track you ✔️
- Very lightweight with no dependencies ✔️
- Single line to get going ✔️
- Single line to get started ✔️

[Live example 1](https://privacylearn.com/?force-consent)
[Live example 2](https://erkinekici.com/?force-consent)
Expand Down Expand Up @@ -83,7 +83,7 @@ ez_consent.init(
privacy_url: "/privacy", // URL that "more" button goes to, default: "/privacy/"
more_button: {
target_attribute : "_blank", // Determines what the behavior of the 'more' button is, default: "_blank", opens the privacy page in a new tab
is_consenting: true // Determines whether clicking on 'more' button gives consent and removes the banner, default: true
is_consenting: true // Controls whether clicking the 'more' button automatically gives consent and removes the banner, default: true
},
texts: {
main: "We use cookies", // The text that's shown on the banner, default: "This website uses cookies & similar."
Expand All @@ -97,15 +97,16 @@ ez_consent.init(
```

The banner will be shown if the user has not yet agreed to read & understand the information.
You can also force to show banner always by having `force-consent` query parameter in URL. E.g. : `test.com/fest?force-consent`
You can force the banner to always show by including the `force-consent` query parameter in the URL.
Example for `https://test.com/fest` page: `test.com/fest?force-consent`.

*[top↑](#ez-consent)*

### 3. Style

#### Existing themes

You can choose one of the following existing theme to get going:
You can choose one of the following existing theme to begin:

##### box-bottom-left.css

Expand Down Expand Up @@ -138,7 +139,7 @@ You're welcome to contribute your theme to the project in [`./src/themes`](./src

## Distributed files

The repository and deployed packages includes a `dist/` folder that adds polyfills to the files and distributes them as:
The repository and deployed packages include a `dist/` folder that adds polyfills to the files and distributes them as:

- minified (`.min.js`, `.min.css`) files for production usage
- non-minified (`.js`, `.css`) files for debugging
Expand Down
24 changes: 12 additions & 12 deletions compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ const inputFile = './src/ez-consent.js';
const cssFolder = './src/themes/';

(async () => {
await deleteFolderRecursiveAsync(outputFolder);
await deleteFolderRecursive(outputFolder);
await fs.promises.mkdir(outputFolder, { recursive: true });
const noModulesCode = (await babel.transformFileAsync(inputFile, {
plugins: ['remove-import-export'],
})).code;
await Promise.all([
compileAsync(noModulesCode, path.join(outputFolder, path.basename(inputFile))),
compileAsync(noModulesCode, path.join(outputFolder, `${removeExtension(path.basename(inputFile))}.min.js`), true),
minifyCssAsync(cssFolder, path.join(outputFolder, 'themes')),
compile(noModulesCode, path.join(outputFolder, path.basename(inputFile))),
compile(noModulesCode, path.join(outputFolder, `${removeExtension(path.basename(inputFile))}.min.js`), true),
minifyCss(cssFolder, path.join(outputFolder, 'themes')),
]);
})().catch((err) => {
console.error(err);
process.exit(-1);
});

async function minifyCssAsync(srcDir, targetDir) {
async function minifyCss(srcDir, targetDir) {
const files = await fs.promises.readdir(srcDir);
const cleanCSS = new CleanCSS();
return Promise.all(files.map(async (name) => {
const filePath = path.join(srcDir, name);
// Copy as it is
// Copy the CSS file without modification
const nonMinifiedTarget = path.join(targetDir, name);
await copyFile(filePath, nonMinifiedTarget);
console.log(`CSS copied to "${nonMinifiedTarget}"`);
console.log(`CSS copied to "${nonMinifiedTarget}".`);
// Minify content
const content = await fs.promises.readFile(filePath, 'utf-8');
const minified = cleanCSS.minify(content).styles;
const targetPath = path.join(targetDir, `${removeExtension(path.basename(name))}.min.css`);
await fs.promises.writeFile(targetPath, minified);
console.log(`CSS minified to "${targetPath}"`);
console.log(`CSS minified to "${targetPath}".`);
}));
}

Expand All @@ -53,7 +53,7 @@ function removeExtension(str) {
return str.slice(0, -path.extname(str).length);
}

async function compileAsync(codeString, targetPath, minifyCode = false) {
async function compile(codeString, targetPath, minifyCode = false) {
try {
await esbuild.build({
stdin: {
Expand All @@ -63,13 +63,13 @@ async function compileAsync(codeString, targetPath, minifyCode = false) {
outfile: targetPath,
minify: minifyCode,
});
console.log(`JavaScript compiled to "${targetPath}" (${minifyCode ? 'minified' : 'not minified'})`);
console.log(`JavaScript compiled to "${targetPath}" (${minifyCode ? 'minified' : 'not minified'}).`);
} catch (error) {
console.error('[ERROR] esbuild', error);
console.error('esbuild failed during compilation:', error);
process.exit(1);
}
}

async function deleteFolderRecursiveAsync(folderPath) {
async function deleteFolderRecursive(folderPath) {
await fs.promises.rm(folderPath, { recursive: true, force: true });
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ez-consent",
"version": "1.2.2",
"description": "🍪 Minimal & vanilla JS only cookie consent banner with no dependencies.",
"description": "🍪 A minimal, vanilla JavaScript cookie consent banner with no dependencies.",
"main": "src/ez-consent.js",
"scripts": {
"compile": "node compile.js",
Expand Down
9 changes: 5 additions & 4 deletions src/ez-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const ez_consent = (() => { // eslint-disable-line camelcase
injectHtmlAsync: (options) => new Promise((resolve) => {
const html = initializeHtml(options);
document.addEventListener(
'DOMContentLoaded', // Wait until "document.body" is ready so we make sure we're first element
'DOMContentLoaded', // Wait until "document.body" is ready to ensure this is the first element inserted
() => {
document.body.insertAdjacentHTML('afterbegin', html);
resolve();
Expand Down Expand Up @@ -141,10 +141,11 @@ export const ez_consent = (() => { // eslint-disable-line camelcase
function fillDefaults(options) {
return objectAssignRecursively(defaults, options || {});
function objectAssignRecursively(target, ...sources) {
// Implemented because Object.assign does not assign nested objects
// options = {...defaults, ...options} works but it's not supported in older JS:
// This is implemented because `Object.assign does` not assign nested objects
// `options = {...defaults, ...options}` works, but it is not supported in
// older JavaScript versions:
// not polyfilled by closure compiler
// babel-plugin-proposal-object-rest-spread just runs Object.assign which
// `babel-plugin-proposal-object-rest-spread` just runs `Object.assign` which
// does not work with nested objects
sources.forEach((source) => {
Object.keys(source).forEach((key) => {
Expand Down

0 comments on commit 1a4ec74

Please sign in to comment.