mirror of
https://github.com/smogon/sprites.git
synced 2026-04-24 23:07:05 -05:00
deploy: basic Path class
This commit is contained in:
parent
dab36f0771
commit
9946c12190
33
tools/deploy/path.ts
Normal file
33
tools/deploy/path.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
import pathlib from 'path';
|
||||
|
||||
type PathAttrs = {dir : string, name : string, ext : string | null};
|
||||
|
||||
export class Path {
|
||||
public readonly dir : string;
|
||||
public readonly name : string;
|
||||
public readonly ext : string | null;
|
||||
|
||||
constructor({dir, name, ext} : PathAttrs) {
|
||||
this.dir = dir;
|
||||
this.name = name;
|
||||
this.ext = ext;
|
||||
}
|
||||
|
||||
static parse(x : string) {
|
||||
const {dir, name, ext} = pathlib.parse(x);
|
||||
return new Path({dir, name, ext: ext === "" ? null : ext.slice(1)});
|
||||
}
|
||||
|
||||
update({dir, name, ext} : Partial<PathAttrs>) {
|
||||
return new Path({dir: dir ?? this.dir,
|
||||
name : name ?? this.name,
|
||||
ext : ext === undefined ? this.ext : ext});
|
||||
}
|
||||
|
||||
format() {
|
||||
return pathlib.format({dir : this.dir,
|
||||
name : this.name,
|
||||
ext : this.ext === null ? "" : `.${this.ext}`});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user