| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import { type_manager } from "./functions.js";
- class file {
- #name;
- #path;
- #extension;
- constructor(path, windows_like = false) {
- if (!type_manager.is_string(path)) {
- throw "Path tu the file must be string.";
- }
- path = path.trim();
- if (path.length === 0) {
- throw "Path of the file can not be empty.";
- }
-
- const separator = windows_like ? "\\" : "/";
- const dirs = path.split(separator);
- const full_filename = dirs.pop().trim();
- const filename_parts = full_filename.split(".");
-
- this.#name = filename_parts.shift();
- this.#extension = filename_parts.join(".")
- this.#path = dirs.join("/");
- }
- get full_path() {
- if (this.#path.length === 0) {
- return this.filename;
- }
- return this.#path + "/" + this.filename;
- }
- get filename() {
- if (this.#extension.length === 0) {
- return this.#name;
- }
- return this.#name + "." + this.#extension;
- }
- get name() {
- return this.#name;
- }
- get extension() {
- return this.#extension;
- }
- get path() {
- return this.#path;
- }
- get type() {
- return this.#extension;
- }
- }
- export { file };
|