Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Oct 27, 2022
1 parent 921c6c2 commit cccb283
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.1

- Cleanup

## 1.1.0

- Introduces filters
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ import compress from "astro-compress";
export default {
integrations: [
compress({
filter: [
exclude: [
"my-awesome.png",
(file: string) =>
file === "./dist/img/favicon/safari-pinned-tab.svg",
Expand Down
2 changes: 1 addition & 1 deletion dist/lib/parse.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { Options } from "../options/index.js";
declare const _default: (glob: string, debug: number | undefined, type: string | undefined, filter: Options["filter"], write?: (data: string) => any, read?: (file: string) => any) => Promise<void>;
declare const _default: (glob: string, debug: number | undefined, type: string | undefined, exclude: Options["exclude"], write?: (data: string) => any, read?: (file: string) => any) => Promise<void>;
export default _default;
2 changes: 1 addition & 1 deletion dist/lib/parse.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/lib/pipe-all.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/options/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export declare type filterFunction = (file: string) => boolean;
export interface Options {
[key: string]: any;
path?: string;
filter?: string | RegExp | filterFunction | [string] | [RegExp] | [filterFunction];
exclude?: string | RegExp | filterFunction | [string] | [RegExp] | [filterFunction];
css?: boolean | CSS;
html?: boolean | HTML;
js?: boolean | JS;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "astro-compress",
"version": "1.1.0",
"version": "1.1.1",
"type": "module",
"description": "🗜️ AstroJS compression utilities. Compress HTML, CSS, JavaScript and more.",
"repository": {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/format-bytes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export default async (bytes: number, decimals = 2) => {
if (bytes === 0) return "0 Bytes";
if (bytes === 0) {
return "0 Bytes";
}

const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
Expand Down
24 changes: 12 additions & 12 deletions src/lib/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default async (
glob: string,
debug: number = 2,
type: string = "",
filter: Options["filter"],
exclude: Options["exclude"],
write: (data: string) => any = async (data) => data,
read: (file: string) => any = async (file) =>
await fs.promises.readFile(file, "utf-8")
Expand All @@ -20,30 +20,30 @@ export default async (
total: 0,
};

let excludes = new Set();
let filters = new Set();

if (typeof filter !== "undefined") {
if (filter instanceof Array) {
for (const filters of filter) {
excludes.add(filters);
if (typeof exclude !== "undefined") {
if (exclude instanceof Array) {
for (const excludes of exclude) {
filters.add(excludes);
}
} else {
excludes.add(filter);
filters.add(exclude);
}
}

for (const exclude of excludes) {
if (typeof exclude === "string") {
for (const filter of filters) {
if (typeof filter === "string") {
for (const file of files) {
if (file.match(exclude)) {
if (file.match(filter)) {
files.splice(files.indexOf(file), 1);
}
}
}

if (typeof exclude === "function") {
if (typeof filter === "function") {
for (const file of files) {
if (exclude(file)) {
if (filter(file)) {
files.splice(files.indexOf(file), 1);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib/pipe-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default async (settings: Options, debug: number = 2) => {
`${settings.path}**/*.css`,
debug,
files,
settings?.filter,
settings?.exclude,
(data) => csso(data, setting).css
);
break;
Expand All @@ -34,7 +34,7 @@ export default async (settings: Options, debug: number = 2) => {
`${settings.path}**/*.html`,
debug,
files,
settings?.filter,
settings?.exclude,
async (data) => await htmlMinifierTerser(data, setting)
);
break;
Expand All @@ -45,7 +45,7 @@ export default async (settings: Options, debug: number = 2) => {
`${settings.path}**/*.{js,mjs,cjs}`,
debug,
files,
settings?.filter,
settings?.exclude,
async (data) => (await terser(data, setting)).code
);
break;
Expand All @@ -56,7 +56,7 @@ export default async (settings: Options, debug: number = 2) => {
`${settings.path}**/*.{avci,avcs,avif,avifs,gif,heic,heics,heif,heifs,jfif,jif,jpe,jpeg,jpg,png,raw,tiff,webp}`,
debug,
files,
settings?.filter,
settings?.exclude,
async (sharpFile) =>
await sharpRead(sharpFile, setting),
async (file) => sharp(file)
Expand All @@ -69,7 +69,7 @@ export default async (settings: Options, debug: number = 2) => {
`${settings.path}**/*.svg`,
debug,
files,
settings?.filter,
settings?.exclude,
async (data) => {
const result = svgo(data, setting) as {
[key: string]: any;
Expand Down
2 changes: 1 addition & 1 deletion src/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface Options {

path?: string;

filter?:
exclude?:
| string
| RegExp
| filterFunction
Expand Down

0 comments on commit cccb283

Please sign in to comment.