Skip to content

Commit 09a363b

Browse files
committed
Merge branch 'dev'
2 parents b38cdb1 + fb7323b commit 09a363b

2 files changed

Lines changed: 129 additions & 29 deletions

File tree

‎.gitignore‎

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,94 @@
1-
# ignore
2-
node_modules
3-
dist
1+
# ==============================================================================
2+
# 1. Core Dependency Folders
3+
# ==============================================================================
4+
node_modules/
5+
jspm_packages/
6+
.pnp/
7+
.pnp.*
8+
9+
# ==============================================================================
10+
# 2. Package Manager Specifics (Lock Files & Overrides Ignored)
11+
# ==============================================================================
12+
13+
# npm
14+
.npm/
15+
anon-doc-*.txt
16+
npm-debug.log*
417
package-lock.json
5-
yarn.lock
18+
19+
# pnpm
20+
.pnpm-store/
21+
store.lock
622
pnpm-lock.yaml
723

8-
logs
9-
*.log
10-
npm-debug.log*
24+
# Yarn Classic (v1) & Yarn Berry (v2+)
1125
yarn-debug.log*
1226
yarn-error.log*
27+
yarn.lock
28+
29+
# Yarn Berry / Modern (v2+) Specifics
30+
.yarn/cache/
31+
.yarn/build-errors.log
32+
.yarn/install-state.gz
33+
34+
# Bun (Modern runtime & package manager)
35+
bun.lockb
36+
bun.lock
37+
.bun/
38+
39+
# Lerna
1340
lerna-debug.log*
14-
.pnpm-debug.log*
41+
42+
# ==============================================================================
43+
# 3. Build Outputs & Bundlers (Rollup, Vite, Webpack, etc.)
44+
# ==============================================================================
45+
dist/
46+
build/
47+
out/
48+
.next/
49+
.nuxt/
50+
.docusaurus/
51+
.turbo/
52+
.cache/
53+
.parcel-cache/
54+
.rollup.cache/
55+
56+
# TypeScript
57+
*.tsbuildinfo
58+
59+
# ==============================================================================
60+
# 4. Logs, Runtime Data & System Files
61+
# ==============================================================================
62+
logs/
63+
*.log
64+
pid
65+
*.pid
66+
*.seed
67+
*.pid.lock
68+
69+
# System Files
70+
.DS_Store
71+
Thumbs.db
72+
73+
# ==============================================================================
74+
# 5. Security & Local Configurations (CRITICAL)
75+
# ==============================================================================
76+
.npmrc
77+
.yarnrc
78+
.env
79+
.env.local
80+
.env.development.local
81+
.env.test.local
82+
.env.production.local
83+
*.pem
84+
85+
# IDEs and Editors
86+
.idea/
87+
.vscode/*
88+
!.vscode/extensions.json
89+
!.vscode/settings.json
90+
*.suo
91+
*.ntvs*
92+
*.njsproj
93+
*.sln
94+
*.sw?

‎src/getValue.js‎

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ const handleCheckbox = (element, prefix = "", suffix = "") => {
210210
const handleDateTime = (element, value, valueType) => {
211211
const inputType = (element.getAttribute("type") || element.type || "").toLowerCase();
212212
let date;
213-
if (value === "$now") {
213+
214+
if (value === "$now" || element.hasAttribute("now")) {
214215
date = new Date();
215216
} else if (value instanceof Date) {
216217
// If it's already a date object, clone it to avoid mutating references
@@ -313,30 +314,15 @@ const handleDateTime = (element, value, valueType) => {
313314
switch (valueType) {
314315
case "getDayName":
315316
const days = [
316-
"Sunday",
317-
"Monday",
318-
"Tuesday",
319-
"Wednesday",
320-
"Thursday",
321-
"Friday",
322-
"Saturday",
317+
"Sunday", "Monday", "Tuesday", "Wednesday",
318+
"Thursday", "Friday", "Saturday",
323319
];
324320
return days[date.getDay()];
325321

326322
case "getMonthName":
327323
const months = [
328-
"January",
329-
"February",
330-
"March",
331-
"April",
332-
"May",
333-
"June",
334-
"July",
335-
"August",
336-
"September",
337-
"October",
338-
"November",
339-
"December",
324+
"January", "February", "March", "April", "May", "June",
325+
"July", "August", "September", "October", "November", "December",
340326
];
341327
return months[date.getMonth()];
342328

@@ -351,6 +337,41 @@ const handleDateTime = (element, value, valueType) => {
351337
hours = hours % 12 || 12; // Convert 0 to 12 for midnight
352338
return `${hours}:${minutes} ${ampm}`;
353339

340+
case "timeTo": {
341+
const diffMs = date.getTime() - Date.now();
342+
let totalSeconds = Math.floor(Math.abs(diffMs) / 1000);
343+
344+
// Fetch requested units, defaulting to all if attribute isn't present
345+
const unitsAttr = element.getAttribute("time-to-units") || "years,months,days,hours,minutes,seconds";
346+
const requestedUnits = unitsAttr.split(',').map(u => u.trim().toLowerCase());
347+
348+
const result = {};
349+
350+
// Using the exact same time approximations as your timeAgo feature
351+
const unitValues = {
352+
years: 31536000,
353+
months: 2592000,
354+
weeks: 604800,
355+
days: 86400,
356+
hours: 3600,
357+
minutes: 60,
358+
seconds: 1
359+
};
360+
361+
// The order matters here (largest to smallest) so we "consume" time properly
362+
const order = ["years", "months", "weeks", "days", "hours", "minutes", "seconds"];
363+
364+
for (const unit of order) {
365+
if (requestedUnits.includes(unit)) {
366+
const val = Math.floor(totalSeconds / unitValues[unit]);
367+
result[unit] = val;
368+
totalSeconds -= val * unitValues[unit]; // subtract the accounted time
369+
}
370+
}
371+
372+
return result;
373+
}
374+
354375
case "timeAgo": {
355376
const diffMs = Date.now() - date.getTime();
356377
const absSecs = Math.floor(Math.abs(diffMs) / 1000);
@@ -423,7 +444,6 @@ const handleDateTime = (element, value, valueType) => {
423444
}
424445
}
425446
};
426-
427447
/**
428448
* Processes a <select> HTML element with the "multiple" attribute to retrieve an array of selected option values.
429449
* Each selected value can have a prefix or suffix added to it if specified.

0 commit comments

Comments
 (0)