deno.land / x / o_folder_file@0.3 / O_folder_file.module.js

O_folder_file.module.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { a_o_mime_type_most_common } from "./a_o_mime_type_most_common.js"
class O_folder_file{
constructor( s ){ this._s = s this.s_folder_name = null this.s_file_name = null this.s_dir_separator = null this.s_windows_drive_letter = null this.s_file_extension = null this.s_file_extension_separator = '.' this.s_folder_name_without_singleanddoubledots = '' this.o_mime_type_guessed_by_file_extension = null this.f_update_all() //official mime/content types // https://www.iana.org/assignments/media-types/application.csv // https://www.iana.org/assignments/media-types/media-types.xhtml // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
} get s(){ return this._s } set s(value){ this._s = value this.f_update_all() }
f_update_all(){
// detect separator this.s_dir_separator = '/' var a_s = Array.from(this.s) var n_count_backslash = a_s.filter(s=>s=='\\').length var n_count_slash = a_s.filter(s=>s=='/').length if(n_count_backslash > n_count_slash){ this.s_dir_separator = '\\' }
// C:\dir\us\asdf.adfs // /home/user/code/asdf.adsf
var a_s_part = this.s.split(this.s_dir_separator) var b_is_file = true if(this.s[this.s.length-1] == this.s_dir_separator){ console.warn(`${this.s} is not a locator to a file but only to a folder because it ends with a dir separator (${this.s_dir_separator})`) b_is_file = false } var s_file_name = a_s_part[a_s_part.length-1] if(s_file_name == ".." || s_file_name == ".."){ console.warn(`${this.s} is not a locator to a file but only to a folder because it ends with one or two dots (${s_file_name})`) b_is_file = false }
if(b_is_file){ this.s_file_name = a_s_part.pop() if(this.s_file_name.includes(this.s_file_extension_separator)){ this.s_file_extension = this.s_file_name.split(this.s_file_extension_separator).pop() this.o_mime_type_guessed_by_file_extension = a_o_mime_type_most_common.filter( o => o.s_file_extension.split(' ').includes("."+this.s_file_extension) )[0] // console.log(this.o_mime_type_guessed_by_file_extension) } }
if(this.s_dir_separator == '\\'){ if(a_s_part[0].includes(':')){ this.s_windows_drive_letter = a_s_part.shift() } } // /1/a/../b/../c/lol/.. -> /1/c/ // /.././../a/b/c/ -> /../../a/b/c/ var a_s_folder_part = [] // var s = a_s_part.join(this.s_dir_separator) // s = s.replaceAll(this.s_dir_separator+'.'+this.s_dir_separator, '') // var a_s_part = s.split(this.s_dir_separator) for(var s_part of a_s_part){ if(s_part == '.' || s_part == ""){ continue } if(s_part == ".."){ if( a_s_folder_part.filter(s=>s != '..').length > 0){ a_s_folder_part.pop() continue }else{ a_s_folder_part.push(s_part) continue }
} a_s_folder_part.push(s_part)
} this.s_folder_name_without_singleanddoubledots = a_s_folder_part.join(this.s_dir_separator)
this.s_folder_name = a_s_part.join(this.s_dir_separator) }
}
export {O_folder_file}
o_folder_file

Version Info

Tagged at
a year ago

External Dependencies

No external dependencies 🎉