age-ts 2.0.2 → 3.0.0

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 GameLord2011
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 GameLord2011
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "name": "age-ts",
3
- "version": "2.0.2",
4
- "description": "A simple React component that calculates your age",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "keywords": [
8
- "calculation",
9
- "react",
10
- "age",
11
- "next-js"
12
- ],
13
- "author": "GameLord2011",
14
- "license": "MIT",
15
- "dependencies": {
16
- "react": "19.2.0",
17
- "react-dom": "19.2.0"
18
- },
19
- "scripts": {
20
- "build": "tsc"
21
- },
22
- "devDependencies": {
23
- "@types/node": "24.8.1",
24
- "@types/react": "19.2.2",
25
- "typescript": "5.8.3"
26
- }
27
- }
1
+ {
2
+ "name": "age-ts",
3
+ "version": "3.0.0",
4
+ "description": "A simple React component that calculates your age",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "keywords": [
8
+ "calculation",
9
+ "react",
10
+ "age",
11
+ "next-js"
12
+ ],
13
+ "author": "GameLord2011",
14
+ "license": "MIT",
15
+ "dependencies": {
16
+ "react": "19.2.0",
17
+ "react-dom": "19.2.0"
18
+ },
19
+ "scripts": {
20
+ "build": "tsc"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "24.8.1",
24
+ "@types/react": "19.2.2",
25
+ "typescript": "5.8.3"
26
+ }
27
+ }
package/readme.md CHANGED
@@ -1,61 +1,61 @@
1
- # Age.ts
2
-
3
- This is a simple NextJs component that calculates your age.
4
-
5
- ## Installation
6
-
7
- Install the package via npm:
8
-
9
- ```bash
10
- npm install age-ts
11
- ```
12
-
13
- pnpm:
14
-
15
- ```bash
16
- pnpm i age-ts
17
- ```
18
-
19
- or yarn:
20
-
21
- ```bash
22
- yarn add age-ts
23
- ```
24
-
25
- ## Usage
26
-
27
- Import the `Age` component and use it in your NextJS application:
28
-
29
- ```tsx
30
- "use-client";
31
-
32
- import Age from "age-ts";
33
-
34
- function App() {
35
- return <Age />;
36
- }
37
-
38
- export default App;
39
- ```
40
-
41
- ## Environment Variable
42
-
43
- Set the `BIRTHDATE` environment variable in the following format:
44
-
45
- ```text
46
- NEXT_PUBLIC_BIRTHDATE = '<your birthdate here>'
47
- ```
48
-
49
- Or just pass the `birthdate` argument through the component like this:
50
-
51
- ```tsx
52
- "use-client";
53
-
54
- import Age from "age-ts";
55
-
56
- function App() {
57
- return <Age birthdate='01-01-2001' />;
58
- }
59
-
60
- export default App;
61
- ```
1
+ # Age.ts
2
+
3
+ This is a simple NextJs component that calculates your age.
4
+
5
+ ## Installation
6
+
7
+ Install the package via npm:
8
+
9
+ ```bash
10
+ npm install age-ts
11
+ ```
12
+
13
+ pnpm:
14
+
15
+ ```bash
16
+ pnpm i age-ts
17
+ ```
18
+
19
+ or yarn:
20
+
21
+ ```bash
22
+ yarn add age-ts
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Import the `Age` component and use it in your NextJS application:
28
+
29
+ ```tsx
30
+ "use-client";
31
+
32
+ import Age from "age-ts";
33
+
34
+ function App() {
35
+ return <Age />;
36
+ }
37
+
38
+ export default App;
39
+ ```
40
+
41
+ ## Environment Variable
42
+
43
+ Set the `BIRTHDATE` environment variable in the following format:
44
+
45
+ ```text
46
+ NEXT_PUBLIC_BIRTHDATE = '<your birthdate here>'
47
+ ```
48
+
49
+ Or just pass the `birthdate` argument through the component like this:
50
+
51
+ ```tsx
52
+ "use-client";
53
+
54
+ import Age from "age-ts";
55
+
56
+ function App() {
57
+ return <Age birthdate='01-01-2001' />;
58
+ }
59
+
60
+ export default App;
61
+ ```
package/tsconfig.json CHANGED
@@ -1,16 +1,16 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES5",
4
- "module": "CommonJS",
5
- "jsx": "react",
6
- "declaration": true,
7
- "declarationDir": "dist",
8
- "outDir": "dist",
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true
13
- },
14
- "include": ["src/**/*"],
15
- "exclude": ["node_modules", "dist"]
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES5",
4
+ "module": "CommonJS",
5
+ "jsx": "react",
6
+ "declaration": true,
7
+ "declarationDir": "dist",
8
+ "outDir": "dist",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true
13
+ },
14
+ "include": ["src/**/*"],
15
+ "exclude": ["node_modules", "dist"]
16
16
  }
@@ -1,33 +0,0 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
6
- on:
7
- release:
8
- types: [created]
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v4
15
- - uses: actions/setup-node@v4
16
- with:
17
- node-version: 20
18
- - run: npm i
19
-
20
- publish-npm:
21
- needs: build
22
- runs-on: ubuntu-latest
23
- steps:
24
- - uses: actions/checkout@v4
25
- - uses: actions/setup-node@v4
26
- with:
27
- node-version: 20
28
- registry-url: https://registry.npmjs.org/
29
- - run: npm i
30
- - run: npm run build
31
- - run: npm publish
32
- env:
33
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/dist/calcage.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare const calculateAge: ({ birthdate }: {
2
- birthdate: string;
3
- }) => Promise<unknown>;
package/dist/calcage.js DELETED
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.calculateAge = void 0;
40
- var calculateAge = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
41
- var birthdate = _b.birthdate;
42
- return __generator(this, function (_c) {
43
- return [2 /*return*/, new Promise(function (resolve) {
44
- var birthDate = new Date(birthdate);
45
- var today = new Date();
46
- var age = today.getFullYear() - birthDate.getFullYear();
47
- var monthDifference = today.getMonth() - birthDate.getMonth();
48
- if (monthDifference < 0 ||
49
- (monthDifference === 0 && today.getDate() < birthDate.getDate())) {
50
- age--;
51
- }
52
- resolve(age);
53
- })];
54
- });
55
- }); };
56
- exports.calculateAge = calculateAge;
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import React from "react";
2
- export default function Age({ birthdate, impress_the_girls_mode }: {
3
- birthdate?: string;
4
- impress_the_girls_mode?: boolean;
5
- }): React.JSX.Element;
package/dist/index.js DELETED
@@ -1,78 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.default = Age;
43
- var calcage_1 = require("./calcage");
44
- var react_1 = __importDefault(require("react"));
45
- var react_2 = require("react");
46
- var react_3 = require("react");
47
- var react_4 = require("react");
48
- function Age(_a) {
49
- var _this = this;
50
- var birthdate = _a.birthdate, impress_the_girls_mode = _a.impress_the_girls_mode;
51
- var _b = (0, react_3.useState)(null), age = _b[0], setAge = _b[1];
52
- var effectiveBirthdate = process.env.NEXT_PUBLIC_BIRTHDATE || birthdate || "";
53
- (0, react_2.useEffect)(function () {
54
- var fetchAge = function () { return __awaiter(_this, void 0, void 0, function () {
55
- var calculatedAge;
56
- return __generator(this, function (_a) {
57
- switch (_a.label) {
58
- case 0:
59
- if (effectiveBirthdate === "") {
60
- throw new Error("I didn't get a birthdate, \nset one on the enviroment variable or ad the \"birthdate\" argument");
61
- }
62
- return [4 /*yield*/, (0, calcage_1.calculateAge)({ birthdate: effectiveBirthdate })];
63
- case 1:
64
- calculatedAge = _a.sent();
65
- if (impress_the_girls_mode) {
66
- calculatedAge++;
67
- }
68
- (0, react_4.startTransition)(function () {
69
- setAge(calculatedAge);
70
- });
71
- return [2 /*return*/];
72
- }
73
- });
74
- }); };
75
- fetchAge();
76
- }, [effectiveBirthdate]);
77
- return react_1.default.createElement(react_1.default.Fragment, null, Number.isNaN(age) ? "Error" : age !== null ? age : "...");
78
- }