jcinfo-utils 1.0.21 → 1.0.22

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.
@@ -0,0 +1,8 @@
1
+ export function formatFileSize(bytes, decimalPoint) {
2
+ if (bytes == 0) return '0 Bytes'
3
+ var k = 1000,
4
+ dm = decimalPoint || 2,
5
+ sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
6
+ i = Math.floor(Math.log(bytes) / Math.log(k))
7
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
8
+ }
package/index.d.ts CHANGED
@@ -10,10 +10,14 @@ export function isDarkMode(): boolean
10
10
 
11
11
  export function colorGain(hex: string, gain: number): string
12
12
 
13
- export function trunc(valor: number = 0, decimais: number = 2): number
13
+ export function trunc(valor?: number, decimais?: number): number
14
14
 
15
- export function random(max: number = 99999999): number
15
+ export function random(max?: number): number
16
16
 
17
- export function getHash(value: string = ''): string
17
+ export function getHash(value?: string): string
18
18
 
19
- export function scrollToTop(smooth: boolean = false): void
19
+ export function scrollToTop(smooth?: boolean): void
20
+
21
+ export function formatFileSize(bytes: number, decimalPoint: number): string
22
+
23
+ export function updateDotEnv(): void
package/index.js CHANGED
@@ -10,6 +10,9 @@ import {
10
10
  getMonthName,
11
11
  } from './dates.js'
12
12
 
13
+ import { updateDotEnv } from './updateDotEnv.js'
14
+ import { formatFileSize } from './formatFileSize.js'
15
+
13
16
  // ===================================================== LOGS
14
17
 
15
18
  function addLog({ ...args }) {
@@ -189,4 +192,6 @@ export {
189
192
  random,
190
193
  trunc,
191
194
  scrollToTop,
195
+ updateDotEnv,
196
+ formatFileSize,
192
197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jcinfo-utils",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "Pacote de funções utilitárias",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/testar.js CHANGED
@@ -18,3 +18,12 @@ console.log(
18
18
  console.log(jc.getHash('jose'))
19
19
 
20
20
  scrollToTop()
21
+
22
+ const value = jc.formatFileSize(156789.88, 3)
23
+ console.log(value)
24
+
25
+ try {
26
+ jc.updateDotEnv()
27
+ } catch (error) {
28
+ console.log('updateDotEnv', error)
29
+ }
@@ -0,0 +1,23 @@
1
+ import fs from 'node:fs'
2
+
3
+ export function updateDotEnv() {
4
+ const keys = ['VITE_VERSION', 'REACT_APP_VERSION']
5
+ let content = fs.readFileSync('.env', 'utf8')
6
+ content = content
7
+ .split('\r\n')
8
+ .map((line) => {
9
+ let [key, value] = line.split('=')
10
+ if (keys.includes(key) && value) {
11
+ let version = value.split(' ')
12
+ let date = new Date()
13
+ let mes = String(date.getMonth() + 1)
14
+ let dia = String(date.getDate()).padStart(2, '0')
15
+ version = version[0] + ` (${mes}${dia})`
16
+ line = key + '=' + version
17
+ console.log('Versão atualizada para:', version)
18
+ }
19
+ return line
20
+ })
21
+ .join('\r\n')
22
+ fs.writeFileSync('.env', content, 'utf8')
23
+ }