{"size": 1943, "ext": "js", "max_stars_repo_path": "src/context/component-meta.js", "max_stars_repo_name": "gchicoye/amphtml", "max_stars_repo_stars_event_min_datetime": "2017-12-05T03:37:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-07T16:29:53.000Z", "max_issues_repo_path": "src/context/component-meta.js", "max_issues_repo_name": "gchicoye/amphtml", "max_issues_repo_issues_event_min_datetime": "2021-08-31T23:38:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T02:29:35.000Z", "max_forks_repo_path": "src/context/component-meta.js", "max_forks_repo_name": "cosmin-vi/amphtml", "max_forks_repo_forks_event_min_datetime": "2017-01-06T21:06:43.000Z", "max_forks_repo_forks_event_max_datetime": "2017-02-28T23:16:21.000Z"}
{"max_stars_count": 3, "max_issues_count": 8, "max_forks_count": 2, "avg_line_length": 25.9066666667, "max_line_length": 79, "alphanum_fraction": 0.671641791}
/**
 * Copyright 2020 The AMP HTML Authors. All Rights Reserved.
 *
 * 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.
 */

const EMPTY_DEPS = [];

/**
 * The following arguments are expected:
 * - a required component function.
 * - an optional array of `ContextProp` dependencies.
 * - an optional string key for a global component identifier.
 *
 * Returns the provided function with metadata attached to it.
 *
 * @param {!Array<!ContextProp>} deps
 * @param {function(...?):?} func
 * @param {string=} opt_key
 * @return {function(...?):?}
 */
export function withMetaData(deps, func, opt_key) {
  return setMetaData(func, deps, opt_key);
}

/**
 * Returns the dependencies attached to the component function. If none
 * available, defaults to an empty array.
 *
 * @param {function(...?):?} func
 * @return {!Array<!ContextProp>}
 * @package
 */
export function getDeps(func) {
  return func['deps'] || EMPTY_DEPS;
}

/**
 * Returns the component's ID. If none is available, defaults to the function's
 * identity.
 *
 * @param {function(...?):?} func
 * @return {*}
 * @package
 */
export function getId(func) {
  return func['key'] || func;
}

/**
 * @param {!Function} func
 * @param {!Array<!ContextProp>|undefined} deps
 * @param {string|undefined} key
 * @return {function(...?):?}
 */
function setMetaData(func, deps, key) {
  if (deps) {
    func['deps'] = deps;
  }
  if (key) {
    func['key'] = key;
  }
  return func;
}
