open-consul/ui/packages/consul-ui/app/helpers/is.js
Ronald 6bcb98ea71
Add UI copyright headers files (#16614)
* Add copyright headers to UI files

* Ensure copywrite file ignores external libs
2023-03-14 09:18:55 -04:00

27 lines
814 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Helper from 'ember-can/helpers/can';
import { get } from '@ember/object';
import { camelize } from '@ember/string';
export const is = (helper, [abilityString, model], properties) => {
let { abilityName, propertyName } = helper.abilities.parse(abilityString);
let ability = helper.abilities.abilityFor(abilityName, model, properties);
if (typeof ability.getCharacteristicProperty === 'function') {
propertyName = ability.getCharacteristicProperty(propertyName);
} else {
propertyName = camelize(`is-${propertyName}`);
}
return get(ability, propertyName);
};
export default class extends Helper {
compute([abilityString, model], properties) {
return is(this, [abilityString, model], properties);
}
}