From 421b97e9bc8e2f076cccfd362f1fea8b69911e12 Mon Sep 17 00:00:00 2001 From: jagi Date: Sun, 12 Mar 2017 19:50:06 +0100 Subject: [PATCH] Delete enum.js --- lib/modules/fields/enum.js | 78 -------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 lib/modules/fields/enum.js diff --git a/lib/modules/fields/enum.js b/lib/modules/fields/enum.js deleted file mode 100644 index 6483086..0000000 --- a/lib/modules/fields/enum.js +++ /dev/null @@ -1,78 +0,0 @@ -import _ from 'lodash'; -import Type from './type.js'; -import Validators from '../validators/validators.js'; -import { check, Match } from 'meteor/check'; - -const enumDefinitionPattern = { - name: String, - identifiers: Match.OneOf(Array, Object) -}; - -const Enum = { - create(definition) { - check(definition, enumDefinitionPattern); - - // Get identifiers and values. - let identifiers; - if (Match.test(definition.identifiers, Array)) { - identifiers = _.zipObject( - definition.identifiers, _.range(definition.identifiers.length) - ); - } - else if (Match.test(definition.identifiers, Object)) { - identifiers = definition.identifiers; - let i = 0; - _.forOwn(identifiers, function(value, key) { - if (_.isNil(value)) { - identifiers[key] = i; - i++; - } - else if (_.isNumber(value)) { - i = value + 1; - } - }); - } - const values = _.values(identifiers); - const keys = _.keys(identifiers); - // Create a new Enum constructor. - const Enum = function Enum(identifier) { - return Enum[identifier]; - }; - Enum.getIdentifiers = function() { - return keys; - }; - Enum.getIdentifier = function(value) { - const index = _.indexOf(values, value); - return keys[index]; - }; - // Set identifiers properties in the class. - _.each(identifiers, (value, name) => { - if (Object.defineProperty) { - Object.defineProperty(Enum, name, { - writable: false, - enumerable: true, - value - }); - } - else { - Enum[name] = value; - } - }); - // Create type definition for the given enum. - Type.create({ - name: definition.name, - class: Enum, - validate(args) { - args.param = values; - Validators.choice(args); - } - }); - // Store enum in the enums list. - this.enums[definition.name] = Enum; - - return Enum; - }, - enums: {} -}; - -export default Enum; \ No newline at end of file