Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
timonson committed Apr 17, 2024
1 parent 9272bc2 commit be37376
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
6 changes: 6 additions & 0 deletions arrays/filtering.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isSingle } from "../collections/length.js";
import { isArray, isNull } from "../type.js";
import { not } from "../booleans/negation.js";
import { propertyEquals } from "../objects/membership.js";

function filter(predicate) {
return (arr) => arr.filter(predicate);
Expand Down Expand Up @@ -55,6 +56,11 @@ function removeDuplicatedProperties(key) {
};
}

export function searchForPropertyEquals(property) {
return (array) => (value) =>
array.filter((obj) => propertyEquals(property)(value)(obj));
}

export {
exclude,
excludeNull,
Expand Down
14 changes: 7 additions & 7 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

/**
@typedef {{
* (bodyMethod: "arrayBuffer", hasStatusCheck?: boolean): (input:RequestInfo, init?:RequestInit) => Promise<ArrayBuffer>;
* (bodyMethod: "blob", hasStatusCheck?: boolean): (input:RequestInfo, init?:RequestInit) => Promise<Blob>;
* (bodyMethod: "formData", hasStatusCheck?: boolean): (input:RequestInfo, init?:RequestInit) => Promise<FormData>;
* (bodyMethod: "json", hasStatusCheck?: boolean): (input:RequestInfo, init?:RequestInit) => Promise<JsonValue>;
* (bodyMethod: "text", hasStatusCheck?: boolean): (input:RequestInfo, init?:RequestInit) => Promise<string>;
* (bodyMethod: "uint8Array", hasStatusCheck?: boolean): (input:RequestInfo, init?:RequestInit) => Promise<Uint8Array>;
* (bodyMethod: "body", hasStatusCheck?: boolean): (input:RequestInfo, init?:RequestInit) => Promise<ReadableStream>;
* (bodyMethod: "arrayBuffer", hasStatusCheck?: boolean): (input:RequestInfo | URL, init?:RequestInit) => Promise<ArrayBuffer>;
* (bodyMethod: "blob", hasStatusCheck?: boolean): (input:RequestInfo | URL, init?:RequestInit) => Promise<Blob>;
* (bodyMethod: "formData", hasStatusCheck?: boolean): (input:RequestInfo | URL, init?:RequestInit) => Promise<FormData>;
* (bodyMethod: "json", hasStatusCheck?: boolean): (input:RequestInfo | URL, init?:RequestInit) => Promise<JsonValue>;
* (bodyMethod: "text", hasStatusCheck?: boolean): (input:RequestInfo | URL, init?:RequestInit) => Promise<string>;
* (bodyMethod: "uint8Array", hasStatusCheck?: boolean): (input:RequestInfo | URL, init?:RequestInit) => Promise<Uint8Array>;
* (bodyMethod: "body", hasStatusCheck?: boolean): (input:RequestInfo | URL, init?:RequestInit) => Promise<ReadableStream>;
[k:string]: any
}} FetchFor
*/
Expand Down
15 changes: 14 additions & 1 deletion objects/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@ function reverseObject(input) {
return reversed;
}

export { reverseObject, setProperty };
/**
* Creates a function that removes a specified property from an object.
* @template T The type of the original object.
* @param {keyof T} propName - The name of the property to remove.
* @returns {(obj: T) => Omit<T, typeof propName>}
*/
function removeProperty(propName) {
return (obj) => {
const { [propName]: _, ...rest } = obj;
return rest;
};
}

export { removeProperty, reverseObject, setProperty };
40 changes: 40 additions & 0 deletions path.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,43 @@ export function getDirname(path) {
export function removeExtension(filename) {
return filename.split(".")[0];
}

const osType = (() => {
const { Deno } = globalThis;
if (typeof Deno?.build?.os === "string") {
return Deno.build.os;
}
const { navigator } = globalThis;
if (navigator?.appVersion?.includes?.("Win")) {
return "windows";
}
return "linux";
})();
const isWindows = osType === "windows";
function assertArg(url) {
url = url instanceof URL ? url : new URL(url);
if (url.protocol !== "file:") {
throw new TypeError("Must be a file URL.");
}
return url;
}
function fromFileUrl1(url) {
url = assertArg(url);
return decodeURIComponent(
url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"),
);
}
function fromFileUrl2(url) {
url = assertArg(url);
let path = decodeURIComponent(
url.pathname.replace(/\//g, "\\").replace(/%(?![0-9A-Fa-f]{2})/g, "%25"),
).replace(/^\\*([A-Za-z]:)(\\|$)/, "$1\\");
if (url.hostname !== "") {
path = `\\\\${url.hostname}${path}`;
}
return path;
}

export function fromFileUrl(url) {
return isWindows ? fromFileUrl2(url) : fromFileUrl1(url);
}
2 changes: 1 addition & 1 deletion strings/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @param {string} str
* @return {boolean}
*/
export function isMail(str) {
export function isEmail(str) {
const regex =
/^(([^<>()\[\]\\,;:\s@"]+@[a-zA-Z0-9\-]+\.([a-zA-Z0-9\-]+\.)*[a-zA-Z]{2,})|(<[^<>()\[\]\\,;:\s@"]+@[a-zA-Z0-9]+\.([a-zA-Z0-9\-]+\.)*[a-zA-Z]{2,}>)|([^<>]+ <[^<>()\[\]\\,;:\s@"]+@[a-zA-Z0-9]+\.([a-zA-Z0-9\-]+\.)*[a-zA-Z]{2,}>))$/;
return regex.test(str);
Expand Down

0 comments on commit be37376

Please sign in to comment.