@artginzburg/experimental
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.declinationOfNum = declinationOfNum; | ||
/** | ||
@@ -13,3 +10,3 @@ * You can test how it works with number = 0, number = 1, number = 2 | ||
*/ | ||
function declinationOfNum(number, words) { | ||
export function declinationOfNum(number, words) { | ||
return words[ | ||
@@ -16,0 +13,0 @@ // @ts-expect-error The length of "words" tuple guarantees the index signature used. |
@@ -1,8 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BytesBase = void 0; | ||
exports.formatBytes = formatBytes; | ||
const units = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; | ||
const unitsBase1000 = units.map((size) => size.replace('i', '')); | ||
exports.BytesBase = { | ||
export const BytesBase = { | ||
Standard: 1024, | ||
@@ -12,5 +8,5 @@ Simplified: 1000, | ||
/** Note: macOS uses base = 1000 to display the size in File Info */ | ||
function formatBytes(bytes, decimals = 2, | ||
export function formatBytes(bytes, decimals = 2, | ||
/** @default 1024 */ | ||
base = exports.BytesBase.Standard) { | ||
base = BytesBase.Standard) { | ||
if (!+bytes) | ||
@@ -20,4 +16,4 @@ return '0 Bytes'; | ||
const i = Math.floor(Math.log(bytes) / Math.log(base)); | ||
return `${parseFloat((bytes / Math.pow(base, i)).toFixed(dm))} ${(base === exports.BytesBase.Simplified ? unitsBase1000 : units)[i]}`; | ||
return `${parseFloat((bytes / Math.pow(base, i)).toFixed(dm))} ${(base === BytesBase.Simplified ? unitsBase1000 : units)[i]}`; | ||
} | ||
//# sourceMappingURL=formatBytes.js.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=type-helpers.js.map |
@@ -1,14 +0,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.typedSplit = typedSplit; | ||
exports.typedJoin = typedJoin; | ||
exports.parseUnitString = parseUnitString; | ||
function typedSplit(word, separator) { | ||
export function typedSplit(word, separator) { | ||
return word.split(separator); | ||
} | ||
/** If you're passing a literal array — remember to use `as const`, otherwise the return type will be `never` */ | ||
function typedJoin(arr, separator) { | ||
export function typedJoin(arr, separator) { | ||
return arr.join(separator); | ||
} | ||
function parseUnitString(unitString) { | ||
export function parseUnitString(unitString) { | ||
const value = parseFloat(unitString); | ||
@@ -15,0 +10,0 @@ const unit = unitString.replace(String(value), ''); |
@@ -1,6 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.specialSchemes = exports.specialProtocols = exports.checkIsSameHostName = exports.checkIsHashAnchor = exports.toAbsoluteURL = void 0; | ||
exports.checkIsAnchorOfCurrentUrl = checkIsAnchorOfCurrentUrl; | ||
exports.checkIsSpecialScheme = checkIsSpecialScheme; | ||
/** | ||
@@ -12,3 +7,3 @@ * Check if the Current Url is same as New Url | ||
*/ | ||
function checkIsAnchorOfCurrentUrl(currentUrl, newUrl) { | ||
export function checkIsAnchorOfCurrentUrl(currentUrl, newUrl) { | ||
const currentUrlObj = new URL(currentUrl); | ||
@@ -33,6 +28,5 @@ const newUrlObj = new URL(newUrl); | ||
*/ | ||
const toAbsoluteURL = (url) => { | ||
export const toAbsoluteURL = (url) => { | ||
return new URL(url, window.location.href).href; | ||
}; | ||
exports.toAbsoluteURL = toAbsoluteURL; | ||
/** | ||
@@ -44,8 +38,7 @@ * Check if it is hash anchor or same page anchor | ||
*/ | ||
const checkIsHashAnchor = (currentUrl, newUrl) => { | ||
const current = new URL((0, exports.toAbsoluteURL)(currentUrl)); | ||
const next = new URL((0, exports.toAbsoluteURL)(newUrl)); | ||
export const checkIsHashAnchor = (currentUrl, newUrl) => { | ||
const current = new URL(toAbsoluteURL(currentUrl)); | ||
const next = new URL(toAbsoluteURL(newUrl)); | ||
return current.href.split('#')[0] === next.href.split('#')[0]; | ||
}; | ||
exports.checkIsHashAnchor = checkIsHashAnchor; | ||
/** | ||
@@ -57,13 +50,12 @@ * Check if it is Same Host name | ||
*/ | ||
const checkIsSameHostName = (currentUrl, newUrl) => { | ||
const current = new URL((0, exports.toAbsoluteURL)(currentUrl)); | ||
const next = new URL((0, exports.toAbsoluteURL)(newUrl)); | ||
export const checkIsSameHostName = (currentUrl, newUrl) => { | ||
const current = new URL(toAbsoluteURL(currentUrl)); | ||
const next = new URL(toAbsoluteURL(newUrl)); | ||
return current.hostname.replace(/^www\./, '') === next.hostname.replace(/^www\./, ''); | ||
}; | ||
exports.checkIsSameHostName = checkIsSameHostName; | ||
exports.specialProtocols = ['tel', 'mailto', 'sms', 'blob', 'download']; | ||
exports.specialSchemes = exports.specialProtocols.map((proto) => `${proto}:`); | ||
function checkIsSpecialScheme(url) { | ||
return exports.specialSchemes.some((scheme) => url.startsWith(scheme)); | ||
export const specialProtocols = ['tel', 'mailto', 'sms', 'blob', 'download']; | ||
export const specialSchemes = specialProtocols.map((proto) => `${proto}:`); | ||
export function checkIsSpecialScheme(url) { | ||
return specialSchemes.some((scheme) => url.startsWith(scheme)); | ||
} | ||
//# sourceMappingURL=url-tools.js.map |
{ | ||
"name": "@artginzburg/experimental", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Buffer zone for my tools that are grouped, but are not huge or organized enough to be a separate library", | ||
@@ -30,3 +30,3 @@ "keywords": [], | ||
}, | ||
"gitHead": "c7a7d4b828f11a0ef9d3842d159398da362808be" | ||
"gitHead": "8bb50278600f39c001d1bd603f003c2389a26a1a" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
85138
64
889