YM
2025-08-07 e5c64590b336221f132ed28ae4ae6dca3e03055c
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
/**
 * Used to cache a stats object for the virtual file.
 * Extracted from the `mock-fs` package.
 *
 * @author Tim Schaub http://tschaub.net/
 * @author `webpack-virtual-modules` Contributors
 * @link https://github.com/tschaub/mock-fs/blob/master/lib/binding.js
 * @link https://github.com/tschaub/mock-fs/blob/master/license.md
 */
import constants from 'constants';
 
export class VirtualStats {
  /**
   * Create a new stats object.
   *
   * @param config Stats properties.
   */
  public constructor(config) {
    for (const key in config) {
      if (!Object.prototype.hasOwnProperty.call(config, key)) {
        continue;
      }
      this[key] = config[key];
    }
  }
 
  /**
   * Check if mode indicates property.
   */
  private _checkModeProperty(property): boolean {
    return ((this as any).mode & constants.S_IFMT) === property;
  }
 
  public isDirectory(): boolean {
    return this._checkModeProperty(constants.S_IFDIR);
  }
 
  public isFile(): boolean {
    return this._checkModeProperty(constants.S_IFREG);
  }
 
  public isBlockDevice(): boolean {
    return this._checkModeProperty(constants.S_IFBLK);
  }
 
  public isCharacterDevice(): boolean {
    return this._checkModeProperty(constants.S_IFCHR);
  }
 
  public isSymbolicLink(): boolean {
    return this._checkModeProperty(constants.S_IFLNK);
  }
 
  public isFIFO(): boolean {
    return this._checkModeProperty(constants.S_IFIFO);
  }
 
  public isSocket(): boolean {
    return this._checkModeProperty(constants.S_IFSOCK);
  }
}