@vettvangur/vanilla 0.0.6 → 0.0.7

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.
Files changed (2) hide show
  1. package/dist/index.esm.js +11 -446
  2. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -1,438 +1,6 @@
1
1
  import path from 'node:path';
2
- import process$1 from 'node:process';
3
- import require$$0 from 'fs';
4
- import require$$1 from 'path';
5
- import require$$2 from 'os';
6
- import require$$3 from 'crypto';
7
-
8
- function getDefaultExportFromCjs (x) {
9
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
10
- }
11
-
12
- var main$1 = {exports: {}};
13
-
14
- var name = "dotenv";
15
- var version = "16.4.5";
16
- var description = "Loads environment variables from .env file";
17
- var main = "lib/main.js";
18
- var types = "lib/main.d.ts";
19
- var exports = {
20
- ".": {
21
- types: "./lib/main.d.ts",
22
- require: "./lib/main.js",
23
- "default": "./lib/main.js"
24
- },
25
- "./config": "./config.js",
26
- "./config.js": "./config.js",
27
- "./lib/env-options": "./lib/env-options.js",
28
- "./lib/env-options.js": "./lib/env-options.js",
29
- "./lib/cli-options": "./lib/cli-options.js",
30
- "./lib/cli-options.js": "./lib/cli-options.js",
31
- "./package.json": "./package.json"
32
- };
33
- var scripts = {
34
- "dts-check": "tsc --project tests/types/tsconfig.json",
35
- lint: "standard",
36
- "lint-readme": "standard-markdown",
37
- pretest: "npm run lint && npm run dts-check",
38
- test: "tap tests/*.js --100 -Rspec",
39
- "test:coverage": "tap --coverage-report=lcov",
40
- prerelease: "npm test",
41
- release: "standard-version"
42
- };
43
- var repository = {
44
- type: "git",
45
- url: "git://github.com/motdotla/dotenv.git"
46
- };
47
- var funding = "https://dotenvx.com";
48
- var keywords = [
49
- "dotenv",
50
- "env",
51
- ".env",
52
- "environment",
53
- "variables",
54
- "config",
55
- "settings"
56
- ];
57
- var readmeFilename = "README.md";
58
- var license = "BSD-2-Clause";
59
- var devDependencies = {
60
- "@definitelytyped/dtslint": "^0.0.133",
61
- "@types/node": "^18.11.3",
62
- decache: "^4.6.1",
63
- sinon: "^14.0.1",
64
- standard: "^17.0.0",
65
- "standard-markdown": "^7.1.0",
66
- "standard-version": "^9.5.0",
67
- tap: "^16.3.0",
68
- tar: "^6.1.11",
69
- typescript: "^4.8.4"
70
- };
71
- var engines = {
72
- node: ">=12"
73
- };
74
- var browser = {
75
- fs: false
76
- };
77
- var require$$4 = {
78
- name: name,
79
- version: version,
80
- description: description,
81
- main: main,
82
- types: types,
83
- exports: exports,
84
- scripts: scripts,
85
- repository: repository,
86
- funding: funding,
87
- keywords: keywords,
88
- readmeFilename: readmeFilename,
89
- license: license,
90
- devDependencies: devDependencies,
91
- engines: engines,
92
- browser: browser
93
- };
94
-
95
- var hasRequiredMain;
96
- function requireMain() {
97
- if (hasRequiredMain) return main$1.exports;
98
- hasRequiredMain = 1;
99
- const fs = require$$0;
100
- const path = require$$1;
101
- const os = require$$2;
102
- const crypto = require$$3;
103
- const packageJson = require$$4;
104
- const version = packageJson.version;
105
- const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
106
-
107
- // Parse src into an Object
108
- function parse(src) {
109
- const obj = {};
110
-
111
- // Convert buffer to string
112
- let lines = src.toString();
113
-
114
- // Convert line breaks to same format
115
- lines = lines.replace(/\r\n?/mg, '\n');
116
- let match;
117
- while ((match = LINE.exec(lines)) != null) {
118
- const key = match[1];
119
-
120
- // Default undefined or null to empty string
121
- let value = match[2] || '';
122
-
123
- // Remove whitespace
124
- value = value.trim();
125
-
126
- // Check if double quoted
127
- const maybeQuote = value[0];
128
-
129
- // Remove surrounding quotes
130
- value = value.replace(/^(['"`])([\s\S]*)\1$/mg, '$2');
131
-
132
- // Expand newlines if double quoted
133
- if (maybeQuote === '"') {
134
- value = value.replace(/\\n/g, '\n');
135
- value = value.replace(/\\r/g, '\r');
136
- }
137
-
138
- // Add to object
139
- obj[key] = value;
140
- }
141
- return obj;
142
- }
143
- function _parseVault(options) {
144
- const vaultPath = _vaultPath(options);
145
-
146
- // Parse .env.vault
147
- const result = DotenvModule.configDotenv({
148
- path: vaultPath
149
- });
150
- if (!result.parsed) {
151
- const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
152
- err.code = 'MISSING_DATA';
153
- throw err;
154
- }
155
-
156
- // handle scenario for comma separated keys - for use with key rotation
157
- // example: DOTENV_KEY="dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod"
158
- const keys = _dotenvKey(options).split(',');
159
- const length = keys.length;
160
- let decrypted;
161
- for (let i = 0; i < length; i++) {
162
- try {
163
- // Get full key
164
- const key = keys[i].trim();
165
-
166
- // Get instructions for decrypt
167
- const attrs = _instructions(result, key);
168
-
169
- // Decrypt
170
- decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
171
- break;
172
- } catch (error) {
173
- // last key
174
- if (i + 1 >= length) {
175
- throw error;
176
- }
177
- // try next key
178
- }
179
- }
180
-
181
- // Parse decrypted .env string
182
- return DotenvModule.parse(decrypted);
183
- }
184
- function _log(message) {
185
- console.log(`[dotenv@${version}][INFO] ${message}`);
186
- }
187
- function _warn(message) {
188
- console.log(`[dotenv@${version}][WARN] ${message}`);
189
- }
190
- function _debug(message) {
191
- console.log(`[dotenv@${version}][DEBUG] ${message}`);
192
- }
193
- function _dotenvKey(options) {
194
- // prioritize developer directly setting options.DOTENV_KEY
195
- if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
196
- return options.DOTENV_KEY;
197
- }
198
-
199
- // secondary infra already contains a DOTENV_KEY environment variable
200
- if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
201
- return process.env.DOTENV_KEY;
202
- }
203
-
204
- // fallback to empty string
205
- return '';
206
- }
207
- function _instructions(result, dotenvKey) {
208
- // Parse DOTENV_KEY. Format is a URI
209
- let uri;
210
- try {
211
- uri = new URL(dotenvKey);
212
- } catch (error) {
213
- if (error.code === 'ERR_INVALID_URL') {
214
- const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development');
215
- err.code = 'INVALID_DOTENV_KEY';
216
- throw err;
217
- }
218
- throw error;
219
- }
220
-
221
- // Get decrypt key
222
- const key = uri.password;
223
- if (!key) {
224
- const err = new Error('INVALID_DOTENV_KEY: Missing key part');
225
- err.code = 'INVALID_DOTENV_KEY';
226
- throw err;
227
- }
228
-
229
- // Get environment
230
- const environment = uri.searchParams.get('environment');
231
- if (!environment) {
232
- const err = new Error('INVALID_DOTENV_KEY: Missing environment part');
233
- err.code = 'INVALID_DOTENV_KEY';
234
- throw err;
235
- }
236
-
237
- // Get ciphertext payload
238
- const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
239
- const ciphertext = result.parsed[environmentKey]; // DOTENV_VAULT_PRODUCTION
240
- if (!ciphertext) {
241
- const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
242
- err.code = 'NOT_FOUND_DOTENV_ENVIRONMENT';
243
- throw err;
244
- }
245
- return {
246
- ciphertext,
247
- key
248
- };
249
- }
250
- function _vaultPath(options) {
251
- let possibleVaultPath = null;
252
- if (options && options.path && options.path.length > 0) {
253
- if (Array.isArray(options.path)) {
254
- for (const filepath of options.path) {
255
- if (fs.existsSync(filepath)) {
256
- possibleVaultPath = filepath.endsWith('.vault') ? filepath : `${filepath}.vault`;
257
- }
258
- }
259
- } else {
260
- possibleVaultPath = options.path.endsWith('.vault') ? options.path : `${options.path}.vault`;
261
- }
262
- } else {
263
- possibleVaultPath = path.resolve(process.cwd(), '.env.vault');
264
- }
265
- if (fs.existsSync(possibleVaultPath)) {
266
- return possibleVaultPath;
267
- }
268
- return null;
269
- }
270
- function _resolveHome(envPath) {
271
- return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath;
272
- }
273
- function _configVault(options) {
274
- _log('Loading env from encrypted .env.vault');
275
- const parsed = DotenvModule._parseVault(options);
276
- let processEnv = process.env;
277
- if (options && options.processEnv != null) {
278
- processEnv = options.processEnv;
279
- }
280
- DotenvModule.populate(processEnv, parsed, options);
281
- return {
282
- parsed
283
- };
284
- }
285
- function configDotenv(options) {
286
- const dotenvPath = path.resolve(process.cwd(), '.env');
287
- let encoding = 'utf8';
288
- const debug = Boolean(options && options.debug);
289
- if (options && options.encoding) {
290
- encoding = options.encoding;
291
- } else {
292
- if (debug) {
293
- _debug('No encoding is specified. UTF-8 is used by default');
294
- }
295
- }
296
- let optionPaths = [dotenvPath]; // default, look for .env
297
- if (options && options.path) {
298
- if (!Array.isArray(options.path)) {
299
- optionPaths = [_resolveHome(options.path)];
300
- } else {
301
- optionPaths = []; // reset default
302
- for (const filepath of options.path) {
303
- optionPaths.push(_resolveHome(filepath));
304
- }
305
- }
306
- }
307
-
308
- // Build the parsed data in a temporary object (because we need to return it). Once we have the final
309
- // parsed data, we will combine it with process.env (or options.processEnv if provided).
310
- let lastError;
311
- const parsedAll = {};
312
- for (const path of optionPaths) {
313
- try {
314
- // Specifying an encoding returns a string instead of a buffer
315
- const parsed = DotenvModule.parse(fs.readFileSync(path, {
316
- encoding
317
- }));
318
- DotenvModule.populate(parsedAll, parsed, options);
319
- } catch (e) {
320
- if (debug) {
321
- _debug(`Failed to load ${path} ${e.message}`);
322
- }
323
- lastError = e;
324
- }
325
- }
326
- let processEnv = process.env;
327
- if (options && options.processEnv != null) {
328
- processEnv = options.processEnv;
329
- }
330
- DotenvModule.populate(processEnv, parsedAll, options);
331
- if (lastError) {
332
- return {
333
- parsed: parsedAll,
334
- error: lastError
335
- };
336
- } else {
337
- return {
338
- parsed: parsedAll
339
- };
340
- }
341
- }
342
-
343
- // Populates process.env from .env file
344
- function config(options) {
345
- // fallback to original dotenv if DOTENV_KEY is not set
346
- if (_dotenvKey(options).length === 0) {
347
- return DotenvModule.configDotenv(options);
348
- }
349
- const vaultPath = _vaultPath(options);
350
-
351
- // dotenvKey exists but .env.vault file does not exist
352
- if (!vaultPath) {
353
- _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
354
- return DotenvModule.configDotenv(options);
355
- }
356
- return DotenvModule._configVault(options);
357
- }
358
- function decrypt(encrypted, keyStr) {
359
- const key = Buffer.from(keyStr.slice(-64), 'hex');
360
- let ciphertext = Buffer.from(encrypted, 'base64');
361
- const nonce = ciphertext.subarray(0, 12);
362
- const authTag = ciphertext.subarray(-16);
363
- ciphertext = ciphertext.subarray(12, -16);
364
- try {
365
- const aesgcm = crypto.createDecipheriv('aes-256-gcm', key, nonce);
366
- aesgcm.setAuthTag(authTag);
367
- return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
368
- } catch (error) {
369
- const isRange = error instanceof RangeError;
370
- const invalidKeyLength = error.message === 'Invalid key length';
371
- const decryptionFailed = error.message === 'Unsupported state or unable to authenticate data';
372
- if (isRange || invalidKeyLength) {
373
- const err = new Error('INVALID_DOTENV_KEY: It must be 64 characters long (or more)');
374
- err.code = 'INVALID_DOTENV_KEY';
375
- throw err;
376
- } else if (decryptionFailed) {
377
- const err = new Error('DECRYPTION_FAILED: Please check your DOTENV_KEY');
378
- err.code = 'DECRYPTION_FAILED';
379
- throw err;
380
- } else {
381
- throw error;
382
- }
383
- }
384
- }
385
-
386
- // Populate process.env with parsed values
387
- function populate(processEnv, parsed, options = {}) {
388
- const debug = Boolean(options && options.debug);
389
- const override = Boolean(options && options.override);
390
- if (typeof parsed !== 'object') {
391
- const err = new Error('OBJECT_REQUIRED: Please check the processEnv argument being passed to populate');
392
- err.code = 'OBJECT_REQUIRED';
393
- throw err;
394
- }
395
-
396
- // Set process.env
397
- for (const key of Object.keys(parsed)) {
398
- if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
399
- if (override === true) {
400
- processEnv[key] = parsed[key];
401
- }
402
- if (debug) {
403
- if (override === true) {
404
- _debug(`"${key}" is already defined and WAS overwritten`);
405
- } else {
406
- _debug(`"${key}" is already defined and was NOT overwritten`);
407
- }
408
- }
409
- } else {
410
- processEnv[key] = parsed[key];
411
- }
412
- }
413
- }
414
- const DotenvModule = {
415
- configDotenv,
416
- _configVault,
417
- _parseVault,
418
- config,
419
- decrypt,
420
- parse,
421
- populate
422
- };
423
- main$1.exports.configDotenv = DotenvModule.configDotenv;
424
- main$1.exports._configVault = DotenvModule._configVault;
425
- main$1.exports._parseVault = DotenvModule._parseVault;
426
- main$1.exports.config = DotenvModule.config;
427
- main$1.exports.decrypt = DotenvModule.decrypt;
428
- main$1.exports.parse = DotenvModule.parse;
429
- main$1.exports.populate = DotenvModule.populate;
430
- main$1.exports = DotenvModule;
431
- return main$1.exports;
432
- }
433
-
434
- var mainExports = requireMain();
435
- var dotenv = /*@__PURE__*/getDefaultExportFromCjs(mainExports);
2
+ import process from 'node:process';
3
+ import dotenv from 'dotenv';
436
4
 
437
5
  /**
438
6
  * @memberof @vettvangur/react
@@ -474,8 +42,7 @@ function dictionary(key, data, culture = 'is-IS') {
474
42
  const notFound = '[Translation not found]';
475
43
  for (const item of data) {
476
44
  if (item.itemKey === key) {
477
- var _item$values$find;
478
- const translation = (_item$values$find = item.values.find(b => b.language === culture)) === null || _item$values$find === void 0 ? void 0 : _item$values$find.value;
45
+ const translation = item.values.find(b => b.language === culture)?.value;
479
46
  return translation || notFound;
480
47
  }
481
48
  }
@@ -554,19 +121,19 @@ async function fetcher({
554
121
  */
555
122
  async function loadEnvFiles(showMessage = true) {
556
123
  // Always load the .env file first
557
- const envFilePath = path.resolve(process$1.cwd(), '.env');
124
+ const envFilePath = path.resolve(process.cwd(), '.env');
558
125
  const baseResult = dotenv.config({
559
126
  path: envFilePath
560
127
  });
561
128
  if (baseResult.error) {
562
129
  console.warn(`Warning: Failed to load environment variables from .env: ${baseResult.error.message}`);
563
130
  }
564
- const env = process$1.env.NODE_ENV || 'development'; // Default to 'development' if NODE_ENV is not set
131
+ const env = process.env.NODE_ENV || 'development'; // Default to 'development' if NODE_ENV is not set
565
132
  const envFile = `.env.${env}`;
566
133
 
567
134
  // Load the specified environment file
568
135
  const result = dotenv.config({
569
- path: path.resolve(process$1.cwd(), envFile)
136
+ path: path.resolve(process.cwd(), envFile)
570
137
  });
571
138
  if (result.error) {
572
139
  throw new Error(`Failed to load environment variables from ${envFile}: ${result.error.message}`);
@@ -587,7 +154,7 @@ function isValidRegex(pattern) {
587
154
  try {
588
155
  new RegExp(pattern);
589
156
  return true;
590
- } catch (_unused) {
157
+ } catch {
591
158
  return false;
592
159
  }
593
160
  }
@@ -782,8 +349,7 @@ function lazyModules(moduleMap, root = document) {
782
349
  if (matchedImporters.length > 0) {
783
350
  Promise.allSettled(matchedImporters.map(importer => importer())).then(results => {
784
351
  results.forEach(result => {
785
- var _result$value;
786
- if (result.status === 'fulfilled' && (_result$value = result.value) !== null && _result$value !== void 0 && (_result$value = _result$value.default) !== null && _result$value !== void 0 && _result$value.init) {
352
+ if (result.status === 'fulfilled' && result.value?.default?.init) {
787
353
  result.value.default.init(target);
788
354
  }
789
355
  });
@@ -808,8 +374,8 @@ function lazyModules(moduleMap, root = document) {
808
374
  * initCoreScripts(() => { console.log('Core scripts initialized'); });
809
375
  */
810
376
  function initCoreScripts(callback = null) {
811
- import(path.resolve(process$1.cwd(), 'scripts', 'core', 'prefetch.ts')).then(module => module.default.init());
812
- import(path.resolve(process$1.cwd(), 'scripts', 'core', 'recaptcha.ts')).then(module => module.default.init());
377
+ import(path.resolve(process.cwd(), 'scripts', 'core', 'prefetch.ts')).then(module => module.default.init());
378
+ import(path.resolve(process.cwd(), 'scripts', 'core', 'recaptcha.ts')).then(module => module.default.init());
813
379
  if (callback) {
814
380
  callback();
815
381
  }
@@ -900,8 +466,7 @@ function onPageShow(moduleMap, initCoreScriptsCallback, callback = null) {
900
466
  */
901
467
  function onHtmxBeforeSwap(callback = null) {
902
468
  document.body.addEventListener('htmx:beforeSwap', e => {
903
- var _document$querySelect;
904
- (_document$querySelect = document.querySelectorAll('.button--loading')) === null || _document$querySelect === void 0 || _document$querySelect.forEach(btn => btn.classList.remove('button--loading'));
469
+ document.querySelectorAll('.button--loading')?.forEach(btn => btn.classList.remove('button--loading'));
905
470
  if (callback) {
906
471
  callback(e);
907
472
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vettvangur/vanilla",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Vettvangur | Vanilla JS Utility Library",
5
5
  "access": "private",
6
6
  "type": "module",