HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/zaklada/html/node_modules/node-haste/lib/ConfigurationTrie.js
/**
 * Copyright 2013 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


/**
 * A data structure to efficiently find configuration for a given resource
 * @class
 * @param {Array.<ProjectConfiguration>} configurations
 */

var node_path = require('path');
function ConfigurationTrie(configurations) {
  this.root = { paths: {} };
  this.configurations = configurations;
  configurations.forEach(this.indexConfiguration, this);
}

ConfigurationTrie.fromObject = function(object) {
  var ProjectConfiguration = require('./resource/ProjectConfiguration');
  return new ConfigurationTrie(object.map(function(r) {
    return ProjectConfiguration.fromObject(r);
  }));
};

ConfigurationTrie.prototype.toObject = function() {
  return this.configurations.map(function(r) {
    return r.toObject();
  });
};

/**
 * @protected
 */
ConfigurationTrie.prototype.indexConfiguration = function(configuration) {
  configuration.getHasteRoots().forEach(function(path) {
    var parts = path.split(node_path.sep);
    var node = this.root;
    for (var i = 0; i < parts.length; i++) {
      var part = parts[i];
      node.paths[part] = node.paths[part] || { paths: {} };
      node = node.paths[part];
    }
    node.configuration = configuration;
  }, this);
};

ConfigurationTrie.prototype.findConfiguration = function(resourcePath) {
  var parts = resourcePath.split(node_path.sep);
  var node = this.root;
  var configuration;
  for (var i = 0; i < parts.length - 1; i++) {
    var part = parts[i];
    if (node.paths[part]) {
      node = node.paths[part];
      configuration = node.configuration || configuration;
    } else {
      break;
    }
  }
  return configuration;
};

module.exports = ConfigurationTrie;