提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.5 KiB

  1. /**
  2. * Used to cache a stats object for the virtual file.
  3. * Extracted from the `mock-fs` package.
  4. *
  5. * @author Tim Schaub http://tschaub.net/
  6. * @author `webpack-virtual-modules` Contributors
  7. * @link https://github.com/tschaub/mock-fs/blob/master/lib/binding.js
  8. * @link https://github.com/tschaub/mock-fs/blob/master/license.md
  9. */
  10. import constants from 'constants';
  11. export class VirtualStats {
  12. /**
  13. * Create a new stats object.
  14. *
  15. * @param config Stats properties.
  16. */
  17. public constructor(config) {
  18. for (const key in config) {
  19. if (!Object.prototype.hasOwnProperty.call(config, key)) {
  20. continue;
  21. }
  22. this[key] = config[key];
  23. }
  24. }
  25. /**
  26. * Check if mode indicates property.
  27. */
  28. private _checkModeProperty(property): boolean {
  29. return ((this as any).mode & constants.S_IFMT) === property;
  30. }
  31. public isDirectory(): boolean {
  32. return this._checkModeProperty(constants.S_IFDIR);
  33. }
  34. public isFile(): boolean {
  35. return this._checkModeProperty(constants.S_IFREG);
  36. }
  37. public isBlockDevice(): boolean {
  38. return this._checkModeProperty(constants.S_IFBLK);
  39. }
  40. public isCharacterDevice(): boolean {
  41. return this._checkModeProperty(constants.S_IFCHR);
  42. }
  43. public isSymbolicLink(): boolean {
  44. return this._checkModeProperty(constants.S_IFLNK);
  45. }
  46. public isFIFO(): boolean {
  47. return this._checkModeProperty(constants.S_IFIFO);
  48. }
  49. public isSocket(): boolean {
  50. return this._checkModeProperty(constants.S_IFSOCK);
  51. }
  52. }