turtb 0.5.0 → 0.5.1

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.
@@ -1,4 +1,4 @@
1
- export const textFileExtensions = ['js', 'html', 'css', 'txt', 'gitignore']
1
+ export const textFileExtensions = ['js', 'html', 'css', 'txt', 'gitignore', 'svg', 'env', 'node_repl_history', 'LICENSE', 'webmanifest']
2
2
  export const jsonFileExtensions = ['json']
3
3
 
4
4
  export const TEXT_FILE = 'text file'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turtb",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "binary for turtledb projects",
5
5
  "repository": "git@github.com:dtudury/turtb.git",
6
6
  "author": "David Tudury <david.tudury@gmail.com>",
@@ -4,9 +4,7 @@ import { logError } from '../lib/utils/logger.js'
4
4
  import { deepEqual } from '../lib/utils/deepEqual.js'
5
5
  import { Recaller } from '../lib/utils/Recaller.js'
6
6
  import { subscribe } from '@parcel/watcher'
7
-
8
- export const isLinesOfTextExtension = path => path.match(/\.(html|css|js|svg|txt|gitignore|env|node_repl_history)$/)
9
- export const isJSONExtension = path => path.match(/\.(json)$/)
7
+ import { BINARY_FILE, JSON_FILE, pathToType } from '../lib/utils/fileTransformer.js'
10
8
 
11
9
  export const encodeTextFile = object => {
12
10
  if (!object || typeof object !== 'object') throw new Error('encodeFile requires an object')
@@ -17,18 +15,18 @@ export const encodeTextFile = object => {
17
15
  const decodeBufferAsFileObject = (buffer, path) => {
18
16
  if (!buffer?.isBuffer?.() && !(buffer instanceof Uint8Array)) return buffer
19
17
  const uint8Array = new Uint8Array(buffer)
20
- const isLinesOfText = isLinesOfTextExtension(path)
21
- const isJSON = isJSONExtension(path)
22
- if (!isLinesOfText && !isJSON) return uint8Array
18
+ const type = pathToType(path)
19
+ if (type === BINARY_FILE) return uint8Array
23
20
  const decoder = new TextDecoder('utf-8')
24
21
  const str = decoder.decode(uint8Array)
25
- if (isLinesOfText) return str.split(/\r?\n/)
26
- try {
27
- return JSON.parse(str)
28
- } catch (err) {
29
- logError(() => console.error(`error parsing (file:${path})`))
30
- return str
22
+ if (type === JSON_FILE) {
23
+ try {
24
+ return JSON.parse(str)
25
+ } catch (err) {
26
+ logError(() => console.error(`error parsing (file:${path})`))
27
+ }
31
28
  }
29
+ return str.split(/\r?\n/)
32
30
  }
33
31
 
34
32
  export const equalFileObjects = (a, b, path) => {