natural-time-js 1.1.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +99 -107
- package/babel.config.cjs +9 -0
- package/dist/astronomy/celestial.d.ts +104 -0
- package/{context.js → dist/astronomy/celestial.js} +99 -176
- package/dist/astronomy/celestial.js.map +1 -0
- package/dist/core/NaturalDate.d.ts +164 -0
- package/dist/core/NaturalDate.js +254 -0
- package/dist/core/NaturalDate.js.map +1 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +118 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/validators.d.ts +140 -0
- package/dist/utils/validators.js +231 -0
- package/dist/utils/validators.js.map +1 -0
- package/jest.config.cjs +29 -0
- package/package.json +23 -3
- package/.github/natural-time-app.jpg +0 -0
- package/index.js +0 -241
- package/utils/validators.js +0 -136
package/utils/validators.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module validators
|
|
3
|
-
* @description Validation utilities for natural time calculations
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { NaturalDate } from '../index.js';
|
|
7
|
-
|
|
8
|
-
const LATITUDE_RANGE = { MIN: -90, MAX: 90 };
|
|
9
|
-
const LONGITUDE_RANGE = { MIN: -180, MAX: 180 };
|
|
10
|
-
const ANGLE_RANGE = { MIN: 0, MAX: 360 };
|
|
11
|
-
|
|
12
|
-
// Add ranges based on NaturalDate class constraints
|
|
13
|
-
const NATURAL_DATE_RANGES = {
|
|
14
|
-
MOON: { MIN: 1, MAX: 14 },
|
|
15
|
-
WEEK: { MIN: 1, MAX: 53 },
|
|
16
|
-
WEEK_OF_MOON: { MIN: 1, MAX: 4 },
|
|
17
|
-
DAY_OF_MOON: { MIN: 1, MAX: 28 },
|
|
18
|
-
DAY_OF_WEEK: { MIN: 1, MAX: 7 }
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Validates if a value is a finite number
|
|
23
|
-
* @param {*} value - Value to validate
|
|
24
|
-
* @returns {boolean} True if value is a valid number
|
|
25
|
-
*/
|
|
26
|
-
export const isValidNumber = (value) => {
|
|
27
|
-
return typeof value === 'number' && Number.isFinite(value) && !Number.isNaN(value);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Validates latitude value
|
|
32
|
-
* @param {number} latitude - Latitude to validate
|
|
33
|
-
* @returns {boolean} True if latitude is valid
|
|
34
|
-
*/
|
|
35
|
-
export const isValidLatitude = (latitude) => {
|
|
36
|
-
return isValidNumber(latitude) &&
|
|
37
|
-
latitude >= LATITUDE_RANGE.MIN &&
|
|
38
|
-
latitude <= LATITUDE_RANGE.MAX;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Validates longitude value
|
|
43
|
-
*/
|
|
44
|
-
export const isValidLongitude = (longitude) => {
|
|
45
|
-
return isValidNumber(longitude) &&
|
|
46
|
-
longitude >= LONGITUDE_RANGE.MIN &&
|
|
47
|
-
longitude <= LONGITUDE_RANGE.MAX;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Validates angle value (0-360 degrees)
|
|
52
|
-
*/
|
|
53
|
-
export const isValidAngle = (angle) => {
|
|
54
|
-
return isValidNumber(angle) &&
|
|
55
|
-
angle >= ANGLE_RANGE.MIN &&
|
|
56
|
-
angle <= ANGLE_RANGE.MAX;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Validates unix timestamp
|
|
61
|
-
*/
|
|
62
|
-
export const isValidTimestamp = (timestamp) => {
|
|
63
|
-
return isValidNumber(timestamp) && timestamp > 0;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Validates NaturalDate instance with complete property checks
|
|
68
|
-
* @param {*} date - Value to validate
|
|
69
|
-
* @returns {boolean} True if value is a valid NaturalDate instance
|
|
70
|
-
*/
|
|
71
|
-
export const isValidNaturalDate = (date) => {
|
|
72
|
-
if (!(date instanceof NaturalDate)) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Basic property validations
|
|
77
|
-
if (!isValidTimestamp(date.unixTime) ||
|
|
78
|
-
!isValidLongitude(date.longitude) ||
|
|
79
|
-
!isValidNumber(date.year)) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Natural calendar validations
|
|
84
|
-
return (
|
|
85
|
-
isValidNumber(date.moon) &&
|
|
86
|
-
date.moon >= NATURAL_DATE_RANGES.MOON.MIN &&
|
|
87
|
-
date.moon <= NATURAL_DATE_RANGES.MOON.MAX &&
|
|
88
|
-
|
|
89
|
-
isValidNumber(date.week) &&
|
|
90
|
-
date.week >= NATURAL_DATE_RANGES.WEEK.MIN &&
|
|
91
|
-
date.week <= NATURAL_DATE_RANGES.WEEK.MAX &&
|
|
92
|
-
|
|
93
|
-
isValidNumber(date.weekOfMoon) &&
|
|
94
|
-
date.weekOfMoon >= NATURAL_DATE_RANGES.WEEK_OF_MOON.MIN &&
|
|
95
|
-
date.weekOfMoon <= NATURAL_DATE_RANGES.WEEK_OF_MOON.MAX &&
|
|
96
|
-
|
|
97
|
-
isValidNumber(date.dayOfMoon) &&
|
|
98
|
-
date.dayOfMoon >= NATURAL_DATE_RANGES.DAY_OF_MOON.MIN &&
|
|
99
|
-
date.dayOfMoon <= NATURAL_DATE_RANGES.DAY_OF_MOON.MAX &&
|
|
100
|
-
|
|
101
|
-
isValidNumber(date.dayOfWeek) &&
|
|
102
|
-
date.dayOfWeek >= NATURAL_DATE_RANGES.DAY_OF_WEEK.MIN &&
|
|
103
|
-
date.dayOfWeek <= NATURAL_DATE_RANGES.DAY_OF_WEEK.MAX &&
|
|
104
|
-
|
|
105
|
-
isValidNumber(date.dayOfYear) &&
|
|
106
|
-
date.dayOfYear >= 1 &&
|
|
107
|
-
date.dayOfYear <= date.yearDuration &&
|
|
108
|
-
|
|
109
|
-
typeof date.isRainbowDay === 'boolean' &&
|
|
110
|
-
isValidAngle(date.time) &&
|
|
111
|
-
isValidTimestamp(date.yearStart) &&
|
|
112
|
-
isValidNumber(date.yearDuration) &&
|
|
113
|
-
isValidTimestamp(date.nadir)
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Validates cache key string
|
|
119
|
-
*/
|
|
120
|
-
export const isValidCacheKey = (key) => {
|
|
121
|
-
return typeof key === 'string' && key.length > 0;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Throws formatted error for invalid parameters
|
|
126
|
-
* @param {string} paramName - Name of the invalid parameter
|
|
127
|
-
* @param {*} value - Invalid value
|
|
128
|
-
* @param {string} expectedType - Description of expected type/format
|
|
129
|
-
* @throws {Error} Formatted validation error
|
|
130
|
-
*/
|
|
131
|
-
export const throwValidationError = (paramName, value, expectedType) => {
|
|
132
|
-
throw new Error(
|
|
133
|
-
`Invalid ${paramName}: ${value}. ` +
|
|
134
|
-
`Expected ${expectedType}`
|
|
135
|
-
);
|
|
136
|
-
};
|