{"version":3,"file":"directory.mjs","names":[],"sources":["../../../../../node_modules/mock-fs/lib/directory.js"],"sourcesContent":["'use strict';\n\nconst util = require('util');\nconst Item = require('./item.js');\nconst constants = require('constants');\n\n/**\n * A directory.\n * @class\n */\nfunction Directory() {\n  Item.call(this);\n\n  /**\n   * Items in this directory.\n   * @type {Object<string, Item>}\n   */\n  this._items = {};\n\n  /**\n   * Permissions.\n   */\n  this._mode = 511; // 0777\n}\nutil.inherits(Directory, Item);\n\n/**\n * Add an item to the directory.\n * @param {string} name The name to give the item.\n * @param {Item} item The item to add.\n * @return {Item} The added item.\n */\nDirectory.prototype.addItem = function (name, item) {\n  if (this._items.hasOwnProperty(name)) {\n    throw new Error('Item with the same name already exists: ' + name);\n  }\n  this._items[name] = item;\n  ++item.links;\n  if (item instanceof Directory) {\n    // for '.' entry\n    ++item.links;\n    // for subdirectory\n    ++this.links;\n  }\n  this.setMTime(new Date());\n  return item;\n};\n\n/**\n * Get a named item.\n * @param {string} name Item name.\n * @return {Item} The named item (or null if none).\n */\nDirectory.prototype.getItem = function (name) {\n  let item = null;\n  if (this._items.hasOwnProperty(name)) {\n    item = this._items[name];\n  }\n  return item;\n};\n\n/**\n * Remove an item.\n * @param {string} name Name of item to remove.\n * @return {Item} The orphan item.\n */\nDirectory.prototype.removeItem = function (name) {\n  if (!this._items.hasOwnProperty(name)) {\n    throw new Error('Item does not exist in directory: ' + name);\n  }\n  const item = this._items[name];\n  delete this._items[name];\n  --item.links;\n  if (item instanceof Directory) {\n    // for '.' entry\n    --item.links;\n    // for subdirectory\n    --this.links;\n  }\n  this.setMTime(new Date());\n  return item;\n};\n\n/**\n * Get list of item names in this directory.\n * @return {Array<string>} Item names.\n */\nDirectory.prototype.list = function () {\n  return Object.keys(this._items).sort();\n};\n\n/**\n * Get directory stats.\n * @param {bolean} bigint Use BigInt.\n * @return {object} Stats properties.\n */\nDirectory.prototype.getStats = function (bigint) {\n  const stats = Item.prototype.getStats.call(this, bigint);\n  const convert = bigint ? (v) => BigInt(v) : (v) => v;\n\n  stats[1] = convert(this.getMode() | constants.S_IFDIR); // mode\n  stats[8] = convert(1); // size\n  stats[9] = convert(1); // blocks\n\n  return stats;\n};\n\n/**\n * Export the constructor.\n * @type {function()}\n */\nmodule.exports = Directory;\n"],"x_google_ignoreList":[0],"mappings":";;;;;CAEA,MAAM,iBAAe,OAAO;CAC5B,MAAM;CACN,MAAM,sBAAoB,YAAY;;;;;CAMtC,SAAS,YAAY;AACnB,OAAK,KAAK,KAAK;;;;;AAMf,OAAK,SAAS,EAAE;;;;AAKhB,OAAK,QAAQ;;AAEf,MAAK,SAAS,WAAW,KAAK;;;;;;;AAQ9B,WAAU,UAAU,UAAU,SAAU,MAAM,MAAM;AAClD,MAAI,KAAK,OAAO,eAAe,KAAK,CAClC,OAAM,IAAI,MAAM,6CAA6C,KAAK;AAEpE,OAAK,OAAO,QAAQ;AACpB,IAAE,KAAK;AACP,MAAI,gBAAgB,WAAW;AAE7B,KAAE,KAAK;AAEP,KAAE,KAAK;;AAET,OAAK,yBAAS,IAAI,MAAM,CAAC;AACzB,SAAO;;;;;;;AAQT,WAAU,UAAU,UAAU,SAAU,MAAM;EAC5C,IAAI,OAAO;AACX,MAAI,KAAK,OAAO,eAAe,KAAK,CAClC,QAAO,KAAK,OAAO;AAErB,SAAO;;;;;;;AAQT,WAAU,UAAU,aAAa,SAAU,MAAM;AAC/C,MAAI,CAAC,KAAK,OAAO,eAAe,KAAK,CACnC,OAAM,IAAI,MAAM,uCAAuC,KAAK;EAE9D,MAAM,OAAO,KAAK,OAAO;AACzB,SAAO,KAAK,OAAO;AACnB,IAAE,KAAK;AACP,MAAI,gBAAgB,WAAW;AAE7B,KAAE,KAAK;AAEP,KAAE,KAAK;;AAET,OAAK,yBAAS,IAAI,MAAM,CAAC;AACzB,SAAO;;;;;;AAOT,WAAU,UAAU,OAAO,WAAY;AACrC,SAAO,OAAO,KAAK,KAAK,OAAO,CAAC,MAAM;;;;;;;AAQxC,WAAU,U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