derafu-js 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Esteban De La Fuente Rubio / Derafu <https://www.derafu.org>
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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Derafu: JS - Why use a JS framework if we can do all from scratch?
2
+
3
+ Please refer to the [documentation](https://www.derafu.dev/docs/ui/js) for more information.
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "derafu-js",
3
+ "version": "0.1.0",
4
+ "description": "Why use a JS framework if we can do all from scratch?",
5
+ "main": "src/derafu.js",
6
+ "files": [
7
+ "src/**/*.js",
8
+ "LICENSE",
9
+ "README.md"
10
+ ],
11
+ "scripts": {
12
+ "lint": "eslint src/",
13
+ "lint:fix": "eslint src/ --fix",
14
+ "lint:check": "eslint src/ --max-warnings=0",
15
+ "format": "prettier --write src/",
16
+ "format:check": "prettier --check src/",
17
+ "test": "jest --forceExit"
18
+ },
19
+ "keywords": [
20
+ "javascript",
21
+ "utility",
22
+ "library",
23
+ "forms",
24
+ "validation",
25
+ "ui"
26
+ ],
27
+ "author": "Derafu DEV",
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/derafu/derafu-js.git"
32
+ },
33
+ "homepage": "https://github.com/derafu/derafu-js#readme",
34
+ "bugs": {
35
+ "url": "https://github.com/derafu/derafu-js/issues"
36
+ },
37
+ "devDependencies": {
38
+ "eslint": "^8.57.0",
39
+ "prettier": "^3.2.5",
40
+ "jest": "^29.7.0",
41
+ "jest-puppeteer": "^10.1.4",
42
+ "puppeteer": "^24.15.0"
43
+ },
44
+ "engines": {
45
+ "node": ">=22.0.0"
46
+ }
47
+ }
package/src/__.js ADDED
@@ -0,0 +1,203 @@
1
+ /*! Generic functions | (c) 2025 Derafu DEV | MIT */
2
+
3
+ // Import all modules.
4
+ // Note: In a browser environment, these modules should be loaded before this
5
+ // file. The modules are: Utils, UI, Validation, Tabs, FormValidation,
6
+ // FormFields, FormTables.
7
+
8
+ // Main object where all functions will be assigned for backward compatibility.
9
+ const __ = {};
10
+
11
+ // Import Utils functions.
12
+ if (typeof Utils !== 'undefined') {
13
+ __.generatePassword = Utils.generatePassword;
14
+ __.getCookie = Utils.getCookie;
15
+ __.getUserLanguage = Utils.getUserLanguage;
16
+ __.num = Utils.num;
17
+ __.empty = Utils.empty;
18
+ __.isInt = Utils.isInt;
19
+ __.isFloat = Utils.isFloat;
20
+ __.keyValues = Utils.keyValues;
21
+ __.selector = Utils.selector;
22
+ } else if (typeof module === 'object' && module.exports) {
23
+ // Node.js environment - import modules directly.
24
+ try {
25
+ const Utils = require('./utils.js');
26
+ __.generatePassword = Utils.generatePassword;
27
+ __.getCookie = Utils.getCookie;
28
+ __.getUserLanguage = Utils.getUserLanguage;
29
+ __.num = Utils.num;
30
+ __.empty = Utils.empty;
31
+ __.isInt = Utils.isInt;
32
+ __.isFloat = Utils.isFloat;
33
+ __.keyValues = Utils.keyValues;
34
+ __.selector = Utils.selector;
35
+ } catch (e) {
36
+ // Module not found, continue
37
+ }
38
+ }
39
+
40
+ // Import UI functions.
41
+ if (typeof UI !== 'undefined') {
42
+ __.popup = UI.popup;
43
+ __.table = UI.table;
44
+ __.notify = UI.notify;
45
+ __.copy = UI.copy;
46
+ __.paste = UI.paste;
47
+ __.share = UI.share;
48
+ __.loading = UI.loading;
49
+ __.alert = UI.alert;
50
+ __.confirm = UI.confirm;
51
+ __.scroll = UI.scroll;
52
+ __.deeplink = UI.deeplink;
53
+ __.print = UI.print;
54
+ } else if (typeof module === 'object' && module.exports) {
55
+ // Node.js environment - import modules directly.
56
+ try {
57
+ const UI = require('./ui.js');
58
+ __.popup = UI.popup;
59
+ __.table = UI.table;
60
+ __.notify = UI.notify;
61
+ __.copy = UI.copy;
62
+ __.paste = UI.paste;
63
+ __.share = UI.share;
64
+ __.loading = UI.loading;
65
+ __.alert = UI.alert;
66
+ __.confirm = UI.confirm;
67
+ __.scroll = UI.scroll;
68
+ __.deeplink = UI.deeplink;
69
+ __.print = UI.print;
70
+ } catch (e) {
71
+ // Module not found, continue
72
+ }
73
+ }
74
+
75
+ // Import Validation functions.
76
+ if (typeof ValidationL10nCl !== 'undefined') {
77
+ __.rut = ValidationL10nCl.rut;
78
+ } else if (typeof module === 'object' && module.exports) {
79
+ // Node.js environment - import modules directly.
80
+ try {
81
+ const ValidationL10nCl = require('./validation/l10n-cl.js');
82
+ __.rut = ValidationL10nCl.rut;
83
+ } catch (e) {
84
+ // Module not found, continue.
85
+ }
86
+ }
87
+
88
+ // Import Tabs functions.
89
+ if (typeof Tabs !== 'undefined') {
90
+ __.tabs = Tabs.init;
91
+ __.tabs_init = Tabs.init_old; // For backward compatibility.
92
+ // Add all tabs methods to the main object.
93
+ __.tabs.handleURLDeeplink = Tabs.handleURLDeeplink;
94
+ __.tabs.handleTabDeeplink = Tabs.handleTabDeeplink;
95
+ __.tabs.addLinksToTabCards = Tabs.addLinksToTabCards;
96
+ __.tabs.bindModalButtons = Tabs.bindModalButtons;
97
+ __.tabs.bindFormElements = Tabs.bindFormElements;
98
+ __.tabs.deeplink = Tabs.deeplink;
99
+ } else if (typeof module === 'object' && module.exports) {
100
+ // Node.js environment - import modules directly.
101
+ try {
102
+ const Tabs = require('./tabs.js');
103
+ __.tabs = Tabs.init;
104
+ __.tabs_init = Tabs.init_old; // For backward compatibility.
105
+ // Add all tabs methods to the main object.
106
+ __.tabs.handleURLDeeplink = Tabs.handleURLDeeplink;
107
+ __.tabs.handleTabDeeplink = Tabs.handleTabDeeplink;
108
+ __.tabs.addLinksToTabCards = Tabs.addLinksToTabCards;
109
+ __.tabs.bindModalButtons = Tabs.bindModalButtons;
110
+ __.tabs.bindFormElements = Tabs.bindFormElements;
111
+ __.tabs.deeplink = Tabs.deeplink;
112
+ } catch (e) {
113
+ // Module not found, continue.
114
+ }
115
+ }
116
+
117
+ // Import Form functions (for backward compatibility).
118
+ if (typeof FormValidation !== 'undefined') {
119
+ __.Form = {};
120
+ __.Form.loading = FormValidation.loading;
121
+ __.Form.alert = FormValidation.alert;
122
+ __.Form.confirm = FormValidation.confirm;
123
+ __.Form.check = FormValidation.check;
124
+ __.Form.check_notempty = FormValidation.check_notempty;
125
+ __.Form.check_real = FormValidation.check_real;
126
+ __.Form.check_email = FormValidation.check_email;
127
+ __.Form.check_rut = FormValidation.check_rut;
128
+ __.Form.getFieldLabel = FormValidation.getFieldLabel;
129
+ } else if (typeof module === 'object' && module.exports) {
130
+ // Node.js environment - import modules directly.
131
+ try {
132
+ const FormValidation = require('./form/validation.js');
133
+ __.Form = {};
134
+ __.Form.loading = FormValidation.loading;
135
+ __.Form.alert = FormValidation.alert;
136
+ __.Form.confirm = FormValidation.confirm;
137
+ __.Form.check = FormValidation.check;
138
+ __.Form.check_notempty = FormValidation.check_notempty;
139
+ __.Form.check_real = FormValidation.check_real;
140
+ __.Form.check_email = FormValidation.check_email;
141
+ __.Form.check_rut = FormValidation.check_rut;
142
+ __.Form.getFieldLabel = FormValidation.getFieldLabel;
143
+ } catch (e) {
144
+ // Module not found, continue.
145
+ }
146
+ }
147
+
148
+ if (typeof FormFields !== 'undefined') {
149
+ if (!__.Form) {
150
+ __.Form = {};
151
+ }
152
+ __.Form.post = FormFields.post;
153
+ __.Form.showPassword = FormFields.showPassword;
154
+ __.Form.growup = FormFields.growup;
155
+ __.Form.fixFields = FormFields.fixFields;
156
+ __.Form.checkboxesSet = FormFields.checkboxesSet;
157
+ __.Form.removeOptions = FormFields.removeOptions;
158
+ __.Form.addOptions = FormFields.addOptions;
159
+ } else if (typeof module === 'object' && module.exports) {
160
+ // Node.js environment - import modules directly.
161
+ try {
162
+ const FormFields = require('./form/fields.js');
163
+ if (!__.Form) {
164
+ __.Form = {};
165
+ }
166
+ __.Form.post = FormFields.post;
167
+ __.Form.showPassword = FormFields.showPassword;
168
+ __.Form.growup = FormFields.growup;
169
+ __.Form.fixFields = FormFields.fixFields;
170
+ __.Form.checkboxesSet = FormFields.checkboxesSet;
171
+ __.Form.removeOptions = FormFields.removeOptions;
172
+ __.Form.addOptions = FormFields.addOptions;
173
+ } catch (e) {
174
+ // Module not found, continue.
175
+ }
176
+ }
177
+
178
+ if (typeof FormTables !== 'undefined') {
179
+ if (!__.Form) {
180
+ __.Form = {};
181
+ }
182
+ __.Form.addJS = FormTables.addJS;
183
+ __.Form.delJS = FormTables.delJS;
184
+ __.Form.updateTablecheck = FormTables.updateTablecheck;
185
+ } else if (typeof module === 'object' && module.exports) {
186
+ // Node.js environment - import modules directly.
187
+ try {
188
+ const FormTables = require('./form/tables.js');
189
+ if (!__.Form) {
190
+ __.Form = {};
191
+ }
192
+ __.Form.addJS = FormTables.addJS;
193
+ __.Form.delJS = FormTables.delJS;
194
+ __.Form.updateTablecheck = FormTables.updateTablecheck;
195
+ } catch (e) {
196
+ // Module not found, continue.
197
+ }
198
+ }
199
+
200
+ // Export module for use in node.js.
201
+ if (typeof module === 'object' && module.exports) {
202
+ module.exports = __;
203
+ }
package/src/derafu.js ADDED
@@ -0,0 +1,140 @@
1
+ /*! Derafu JS - Main entry point | (c) 2025 Derafu DEV | MIT */
2
+
3
+ // Main object where all functions will be assigned.
4
+ const derafu = {
5
+ utils: {},
6
+ ui: {},
7
+ validation: {
8
+ l10n: {
9
+ cl: {},
10
+ },
11
+ },
12
+ form: {},
13
+ tabs: {},
14
+ };
15
+
16
+ // Import Utils functions.
17
+ if (typeof Utils !== 'undefined') {
18
+ derafu.utils.generatePassword = Utils.generatePassword;
19
+ derafu.utils.getCookie = Utils.getCookie;
20
+ derafu.utils.getUserLanguage = Utils.getUserLanguage;
21
+ derafu.utils.num = Utils.num;
22
+ derafu.utils.empty = Utils.empty;
23
+ derafu.utils.isInt = Utils.isInt;
24
+ derafu.utils.isFloat = Utils.isFloat;
25
+ derafu.utils.keyValues = Utils.keyValues;
26
+ derafu.utils.selector = Utils.selector;
27
+ } else if (typeof module === 'object' && module.exports) {
28
+ // Node.js environment - import modules directly.
29
+ try {
30
+ const Utils = require('./utils.js');
31
+ derafu.utils.generatePassword = Utils.generatePassword;
32
+ derafu.utils.getCookie = Utils.getCookie;
33
+ derafu.utils.getUserLanguage = Utils.getUserLanguage;
34
+ derafu.utils.num = Utils.num;
35
+ derafu.utils.empty = Utils.empty;
36
+ derafu.utils.isInt = Utils.isInt;
37
+ derafu.utils.isFloat = Utils.isFloat;
38
+ derafu.utils.keyValues = Utils.keyValues;
39
+ derafu.utils.selector = Utils.selector;
40
+ } catch (e) {
41
+ // Module not found, continue.
42
+ }
43
+ }
44
+
45
+ // Import UI functions.
46
+ if (typeof UI !== 'undefined') {
47
+ derafu.ui.popup = UI.popup;
48
+ derafu.ui.table = UI.table;
49
+ derafu.ui.notify = UI.notify;
50
+ derafu.ui.copy = UI.copy;
51
+ derafu.ui.paste = UI.paste;
52
+ derafu.ui.share = UI.share;
53
+ derafu.ui.loading = UI.loading;
54
+ derafu.ui.alert = UI.alert;
55
+ derafu.ui.confirm = UI.confirm;
56
+ derafu.ui.scroll = UI.scroll;
57
+ derafu.ui.deeplink = UI.deeplink;
58
+ derafu.ui.print = UI.print;
59
+ } else if (typeof module === 'object' && module.exports) {
60
+ // Node.js environment - import modules directly.
61
+ try {
62
+ const UI = require('./ui.js');
63
+ derafu.ui.popup = UI.popup;
64
+ derafu.ui.table = UI.table;
65
+ derafu.ui.notify = UI.notify;
66
+ derafu.ui.copy = UI.copy;
67
+ derafu.ui.paste = UI.paste;
68
+ derafu.ui.share = UI.share;
69
+ derafu.ui.loading = UI.loading;
70
+ derafu.ui.alert = UI.alert;
71
+ derafu.ui.confirm = UI.confirm;
72
+ derafu.ui.scroll = UI.scroll;
73
+ derafu.ui.deeplink = UI.deeplink;
74
+ derafu.ui.print = UI.print;
75
+ } catch (e) {
76
+ // Module not found, continue.
77
+ }
78
+ }
79
+
80
+ // Import Validation functions.
81
+ if (typeof ValidationL10nCl !== 'undefined') {
82
+ derafu.validation.l10n.cl.rut = ValidationL10nCl.rut;
83
+ derafu.validation.l10n.cl.dv = ValidationL10nCl.dv;
84
+ } else if (typeof module === 'object' && module.exports) {
85
+ // Node.js environment - import modules directly.
86
+ try {
87
+ const ValidationL10nCl = require('./validation/l10n-cl.js');
88
+ derafu.validation.l10n.cl.rut = ValidationL10nCl.rut;
89
+ derafu.validation.l10n.cl.dv = ValidationL10nCl.dv;
90
+ } catch (e) {
91
+ // Module not found, continue.
92
+ }
93
+ }
94
+
95
+ // Import Tabs functions.
96
+ if (typeof Tabs !== 'undefined') {
97
+ derafu.tabs.init = Tabs.init;
98
+ derafu.tabs.init_old = Tabs.init_old; // For backward compatibility.
99
+ // Add all tabs methods to the tabs object.
100
+ derafu.tabs.handleURLDeeplink = Tabs.handleURLDeeplink;
101
+ derafu.tabs.handleTabDeeplink = Tabs.handleTabDeeplink;
102
+ derafu.tabs.addLinksToTabCards = Tabs.addLinksToTabCards;
103
+ derafu.tabs.bindModalButtons = Tabs.bindModalButtons;
104
+ derafu.tabs.bindFormElements = Tabs.bindFormElements;
105
+ derafu.tabs.deeplink = Tabs.deeplink;
106
+ } else if (typeof module === 'object' && module.exports) {
107
+ // Node.js environment - import modules directly.
108
+ try {
109
+ const Tabs = require('./tabs.js');
110
+ derafu.tabs.init = Tabs.init;
111
+ derafu.tabs.init_old = Tabs.init_old; // For backward compatibility.
112
+ // Add all tabs methods to the tabs object.
113
+ derafu.tabs.handleURLDeeplink = Tabs.handleURLDeeplink;
114
+ derafu.tabs.handleTabDeeplink = Tabs.handleTabDeeplink;
115
+ derafu.tabs.addLinksToTabCards = Tabs.addLinksToTabCards;
116
+ derafu.tabs.bindModalButtons = Tabs.bindModalButtons;
117
+ derafu.tabs.bindFormElements = Tabs.bindFormElements;
118
+ derafu.tabs.deeplink = Tabs.deeplink;
119
+ } catch (e) {
120
+ // Module not found, continue.
121
+ }
122
+ }
123
+
124
+ // Import Form functions.
125
+ if (typeof Form !== 'undefined') {
126
+ derafu.form = Form;
127
+ } else if (typeof module === 'object' && module.exports) {
128
+ // Node.js environment - import modules directly.
129
+ try {
130
+ const Form = require('./form.js');
131
+ derafu.form = Form;
132
+ } catch (e) {
133
+ // Module not found, continue.
134
+ }
135
+ }
136
+
137
+ // Export module for use in Node.js.
138
+ if (typeof module === 'object' && module.exports) {
139
+ module.exports = derafu;
140
+ }