@magicyan/core
Advanced tools
| 'use strict'; | ||
| const validation = require('./validation.cjs'); | ||
| function notFound(value) { | ||
@@ -7,6 +9,6 @@ return value !== null ? value : void 0; | ||
| function brBuilder(...texts) { | ||
| return texts.flat().filter(nonNullish).join("\n"); | ||
| return texts.flat().filter(validation.isDefined).map((txt) => `${txt}`).join("\n"); | ||
| } | ||
| function spaceBuilder(...texts) { | ||
| return texts.flat().filter(nonNullish).join(" "); | ||
| return texts.flat().filter(validation.isDefined).map((txt) => `${txt}`).join(" "); | ||
| } | ||
@@ -16,3 +18,3 @@ function replaceText(text, replaces) { | ||
| for (const prop in replaces) { | ||
| result = result.replaceAll(prop, replaces[prop]); | ||
| result = result.replaceAll(prop, `${replaces[prop]}`); | ||
| } | ||
@@ -30,5 +32,2 @@ return result; | ||
| } | ||
| function nonNullish(v) { | ||
| return v !== null && v !== void 0; | ||
| } | ||
@@ -35,0 +34,0 @@ exports.brBuilder = brBuilder; |
@@ -0,1 +1,3 @@ | ||
| import { isDefined } from './validation.mjs'; | ||
| function notFound(value) { | ||
@@ -5,6 +7,6 @@ return value !== null ? value : void 0; | ||
| function brBuilder(...texts) { | ||
| return texts.flat().filter(nonNullish).join("\n"); | ||
| return texts.flat().filter(isDefined).map((txt) => `${txt}`).join("\n"); | ||
| } | ||
| function spaceBuilder(...texts) { | ||
| return texts.flat().filter(nonNullish).join(" "); | ||
| return texts.flat().filter(isDefined).map((txt) => `${txt}`).join(" "); | ||
| } | ||
@@ -14,3 +16,3 @@ function replaceText(text, replaces) { | ||
| for (const prop in replaces) { | ||
| result = result.replaceAll(prop, replaces[prop]); | ||
| result = result.replaceAll(prop, `${replaces[prop]}`); | ||
| } | ||
@@ -28,6 +30,3 @@ return result; | ||
| } | ||
| function nonNullish(v) { | ||
| return v !== null && v !== void 0; | ||
| } | ||
| export { brBuilder, capitalize, limitText, notFound, replaceText, spaceBuilder }; |
@@ -12,5 +12,13 @@ 'use strict'; | ||
| } | ||
| function isDefined(value) { | ||
| return value !== null && value !== void 0; | ||
| } | ||
| function isPromise(value) { | ||
| return typeof value === "object" && value !== null && typeof value.then === "function"; | ||
| } | ||
| exports.isDefined = isDefined; | ||
| exports.isEmail = isEmail; | ||
| exports.isNumeric = isNumeric; | ||
| exports.isPromise = isPromise; | ||
| exports.isUrl = isUrl; |
@@ -10,3 +10,9 @@ function isEmail(email) { | ||
| } | ||
| function isDefined(value) { | ||
| return value !== null && value !== void 0; | ||
| } | ||
| function isPromise(value) { | ||
| return typeof value === "object" && value !== null && typeof value.then === "function"; | ||
| } | ||
| export { isEmail, isNumeric, isUrl }; | ||
| export { isDefined, isEmail, isNumeric, isPromise, isUrl }; |
+2
-0
@@ -31,6 +31,8 @@ 'use strict'; | ||
| exports.includesIgnoreCase = check.includesIgnoreCase; | ||
| exports.isDefined = validation.isDefined; | ||
| exports.isEmail = validation.isEmail; | ||
| exports.isNumeric = validation.isNumeric; | ||
| exports.isPromise = validation.isPromise; | ||
| exports.isUrl = validation.isUrl; | ||
| exports.withProperties = _with.withProperties; | ||
| exports.withTimeout = _with.withTimeout; |
+9
-4
@@ -43,3 +43,6 @@ type Color = `#${string}` | string; | ||
| type MaybeString = string | null | undefined; | ||
| type CanBeString = string | { | ||
| toString(): string; | ||
| }; | ||
| type MaybeString = CanBeString | null | undefined; | ||
| /** | ||
@@ -120,3 +123,3 @@ * Ensures that a value is either kept as is (if not `null`) or converted to `undefined`. | ||
| */ | ||
| declare function replaceText<R extends Record<string, any>>(text: string, replaces: R): string; | ||
| declare function replaceText<R extends Record<string, CanBeString>>(text: string, replaces: R): string; | ||
| /** | ||
@@ -299,2 +302,4 @@ * Capitalizes the first letter of a given word, or all words in a phrase if `allWords` is true. | ||
| declare function isNumeric(text: string): boolean; | ||
| declare function isDefined<T>(value: T): value is NonNullable<T>; | ||
| declare function isPromise<T = unknown>(value: unknown): value is Promise<T>; | ||
@@ -343,3 +348,3 @@ /** | ||
| export { brBuilder, capitalize, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isEmail, isNumeric, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, withProperties, withTimeout }; | ||
| export type { MaybeString }; | ||
| export { brBuilder, capitalize, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isDefined, isEmail, isNumeric, isPromise, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, withProperties, withTimeout }; | ||
| export type { CanBeString, MaybeString }; |
+9
-4
@@ -43,3 +43,6 @@ type Color = `#${string}` | string; | ||
| type MaybeString = string | null | undefined; | ||
| type CanBeString = string | { | ||
| toString(): string; | ||
| }; | ||
| type MaybeString = CanBeString | null | undefined; | ||
| /** | ||
@@ -120,3 +123,3 @@ * Ensures that a value is either kept as is (if not `null`) or converted to `undefined`. | ||
| */ | ||
| declare function replaceText<R extends Record<string, any>>(text: string, replaces: R): string; | ||
| declare function replaceText<R extends Record<string, CanBeString>>(text: string, replaces: R): string; | ||
| /** | ||
@@ -299,2 +302,4 @@ * Capitalizes the first letter of a given word, or all words in a phrase if `allWords` is true. | ||
| declare function isNumeric(text: string): boolean; | ||
| declare function isDefined<T>(value: T): value is NonNullable<T>; | ||
| declare function isPromise<T = unknown>(value: unknown): value is Promise<T>; | ||
@@ -343,3 +348,3 @@ /** | ||
| export { brBuilder, capitalize, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isEmail, isNumeric, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, withProperties, withTimeout }; | ||
| export type { MaybeString }; | ||
| export { brBuilder, capitalize, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isDefined, isEmail, isNumeric, isPromise, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, withProperties, withTimeout }; | ||
| export type { CanBeString, MaybeString }; |
+9
-4
@@ -43,3 +43,6 @@ type Color = `#${string}` | string; | ||
| type MaybeString = string | null | undefined; | ||
| type CanBeString = string | { | ||
| toString(): string; | ||
| }; | ||
| type MaybeString = CanBeString | null | undefined; | ||
| /** | ||
@@ -120,3 +123,3 @@ * Ensures that a value is either kept as is (if not `null`) or converted to `undefined`. | ||
| */ | ||
| declare function replaceText<R extends Record<string, any>>(text: string, replaces: R): string; | ||
| declare function replaceText<R extends Record<string, CanBeString>>(text: string, replaces: R): string; | ||
| /** | ||
@@ -299,2 +302,4 @@ * Capitalizes the first letter of a given word, or all words in a phrase if `allWords` is true. | ||
| declare function isNumeric(text: string): boolean; | ||
| declare function isDefined<T>(value: T): value is NonNullable<T>; | ||
| declare function isPromise<T = unknown>(value: unknown): value is Promise<T>; | ||
@@ -343,3 +348,3 @@ /** | ||
| export { brBuilder, capitalize, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isEmail, isNumeric, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, withProperties, withTimeout }; | ||
| export type { MaybeString }; | ||
| export { brBuilder, capitalize, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isDefined, isEmail, isNumeric, isPromise, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, withProperties, withTimeout }; | ||
| export type { CanBeString, MaybeString }; |
+1
-1
@@ -6,3 +6,3 @@ export { hexToRgb, rgbToHex } from './functions/convert.mjs'; | ||
| export { equalsIgnoreCase, includesIgnoreCase } from './functions/check.mjs'; | ||
| export { isEmail, isNumeric, isUrl } from './functions/validation.mjs'; | ||
| export { isDefined, isEmail, isNumeric, isPromise, isUrl } from './functions/validation.mjs'; | ||
| export { withProperties, withTimeout } from './functions/with.mjs'; |
+1
-1
| { | ||
| "name": "@magicyan/core", | ||
| "version": "1.1.0", | ||
| "version": "1.1.1", | ||
| "description": "Template description", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
52387
2.78%656
2.66%