{"_id":"s-enum","_rev":"8-5e54ee63d60a532eb816b345806c8b93","name":"s-enum","description":"SEnum = Super Enum Factory","dist-tags":{"latest":"1.1.5"},"versions":{"1.1.0":{"name":"s-enum","version":"1.1.0","description":"SEnum = Super Enum Factory","main":"dist/s_enum.cjs.js","jsnext:main":"dist/s_enum.es2015.js","scripts":{"build":"build","test":"jest"},"jest":{"unmockedModulePathPatterns":["<rootDir>/node_modules/lodash"]},"repository":{"type":"git","url":"git+https://github.com/zeroasterisk/npm-s-enum.git"},"keywords":["enum","factory"],"author":{"name":"Alan Blount","email":"alan@zeroasterisk.com"},"license":"MIT","bugs":{"url":"https://github.com/zeroasterisk/npm-s-enum/issues"},"homepage":"https://github.com/zeroasterisk/npm-s-enum#readme","devDependencies":{"babel-jest":"^10.0.2","babel-plugin-lodash":"^2.2.2","babel-preset-es2015":"^6.6.0","jest-cli":"^0.10.2","lodash":"^4.10.0"},"dependencies":{"lodash":"^4.10.0"},"gitHead":"56241774890060b3bea9cb11f62fd117edb5c7d1","_id":"s-enum@1.1.0","_shasum":"e407f7aa64a77dba6a38bf618f6c25b478898374","_from":".","_npmVersion":"3.8.5","_nodeVersion":"4.2.1","_npmUser":{"name":"zeroasterisk","email":"alan@zeroasterisk.com"},"dist":{"shasum":"e407f7aa64a77dba6a38bf618f6c25b478898374","tarball":"https://registry.npmjs.org/s-enum/-/s-enum-1.1.0.tgz","integrity":"sha512-Vngg+ezQl98urm8eRKp9PeVsNNsl/XNX7tn4WJT/bDkBwMxsUtEFn7l6We+V5fNry9lzOW6/zBB6cQTrGiHf1Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCHho4DsmGUi/0p6Tzxs1alBu+RGfO5CStQQceA96JGGwIhAIk/lAjpg4RyOtDTDvKAwJX4DzcbMd0gFECGa6zETIpc"}]},"maintainers":[{"name":"zeroasterisk","email":"alan@zeroasterisk.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/s-enum-1.1.0.tgz_1460471188619_0.18615197599865496"}},"1.1.1":{"name":"s-enum","version":"1.1.1","description":"SEnum = Super Enum Factory","main":"dist/s_enum.cjs.js","jsnext:main":"dist/s_enum.es6.js","scripts":{"build":"build","test":"jest"},"jest":{"unmockedModulePathPatterns":["<rootDir>/node_modules/lodash"]},"repository":{"type":"git","url":"git+https://github.com/zeroasterisk/npm-s-enum.git"},"keywords":["enum","factory"],"author":{"name":"Alan Blount","email":"alan@zeroasterisk.com"},"license":"MIT","bugs":{"url":"https://github.com/zeroasterisk/npm-s-enum/issues"},"homepage":"https://github.com/zeroasterisk/npm-s-enum#readme","devDependencies":{"babel-eslint":"^6.0.0","babel-jest":"^10.0.2","babel-plugin-lodash":"^2.2.2","babel-preset-es2015":"^6.6.0","babel-preset-es2015-rollup":"^1.1.1","eslint":"^2.5.3","jest-cli":"^0.10.2","source-map-support":"^0.4.0"},"dependencies":{"lodash":"^4.10.0"},"gitHead":"420ad464fa6df0308453504d55d968f1155090e8","_id":"s-enum@1.1.1","_shasum":"5db768adde3bcc207884eef8518d89b1fabf5bdc","_from":".","_npmVersion":"3.8.5","_nodeVersion":"4.2.1","_npmUser":{"name":"zeroasterisk","email":"alan@zeroasterisk.com"},"dist":{"shasum":"5db768adde3bcc207884eef8518d89b1fabf5bdc","tarball":"https://registry.npmjs.org/s-enum/-/s-enum-1.1.1.tgz","integrity":"sha512-Geu4bkG+Vwi5kT31zpIJAuMaNyrAe5j/Zfmd96rhnC8yIJnR7Rl6O1BczbV0+US2NVqYf9Si0A7v0z3EBGxjrA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDAyO6ZN1X206V1DoDcUcbrMVHQW0rzfezG+nK2k8BsSgIhAKhQT7x8ro8PoyefJxyjMU5e0tFH7yPGMhI+fHzR6rLO"}]},"maintainers":[{"name":"zeroasterisk","email":"alan@zeroasterisk.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/s-enum-1.1.1.tgz_1460490439614_0.5281891212798655"}},"1.1.2":{"name":"s-enum","version":"1.1.2","description":"SEnum = Super Enum Factory","main":"dist/s_enum.cjs.js","jsnext:main":"dist/s_enum.es6.js","scripts":{"build":"build","test":"jest"},"jest":{"unmockedModulePathPatterns":["<rootDir>/node_modules/lodash"]},"repository":{"type":"git","url":"git+https://github.com/zeroasterisk/npm-s-enum.git"},"keywords":["enum","factory"],"author":{"name":"Alan Blount","email":"alan@zeroasterisk.com"},"license":"MIT","bugs":{"url":"https://github.com/zeroasterisk/npm-s-enum/issues"},"homepage":"https://github.com/zeroasterisk/npm-s-enum#readme","devDependencies":{"babel-eslint":"^6.0.0","babel-jest":"^10.0.2","babel-plugin-lodash":"^2.2.2","babel-preset-es2015":"^6.6.0","babel-preset-es2015-rollup":"^1.1.1","eslint":"^2.5.3","jest-cli":"^0.10.2","source-map-support":"^0.4.0"},"dependencies":{"lodash":"^4.10.0"},"gitHead":"1df3c83227a18725fb74d38a4b2bbda12bbc4e01","_id":"s-enum@1.1.2","_shasum":"84cafc37332cccf66cf8f0ebe94bd3e597dff5a0","_from":".","_npmVersion":"3.8.5","_nodeVersion":"4.2.1","_npmUser":{"name":"zeroasterisk","email":"alan@zeroasterisk.com"},"dist":{"shasum":"84cafc37332cccf66cf8f0ebe94bd3e597dff5a0","tarball":"https://registry.npmjs.org/s-enum/-/s-enum-1.1.2.tgz","integrity":"sha512-stAFBqGoDX5+zCBQEDnm7StdH+Z8tPPD8UUP0tTFaXUIW6+82Mty/8mc1X/j6hNM6Nzq4HVPlceQqpUvToerqg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDTzUwX0fmPWWBWGnYCtjNywx9LnzFAKQoZDTFX4QF5uAIhAOGEdCkB3pt2t6xzhI78aCaHC8KOJyagu5HBLuWCyVT9"}]},"maintainers":[{"name":"zeroasterisk","email":"alan@zeroasterisk.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/s-enum-1.1.2.tgz_1460490689570_0.32501865085214376"}},"1.1.3":{"name":"s-enum","version":"1.1.3","description":"SEnum = Super Enum Factory","main":"dist/s_enum.cjs.js","jsnext:main":"dist/s_enum.es6.js","scripts":{"build":"build","test":"jest"},"jest":{"unmockedModulePathPatterns":["<rootDir>/node_modules/lodash"]},"repository":{"type":"git","url":"git+https://github.com/zeroasterisk/npm-s-enum.git"},"keywords":["enum","factory"],"author":{"name":"Alan Blount","email":"alan@zeroasterisk.com"},"license":"MIT","bugs":{"url":"https://github.com/zeroasterisk/npm-s-enum/issues"},"homepage":"https://github.com/zeroasterisk/npm-s-enum#readme","devDependencies":{"babel-eslint":"^6.0.0","babel-jest":"^10.0.2","babel-plugin-lodash":"^2.2.2","babel-preset-es2015":"^6.6.0","babel-preset-es2015-rollup":"^1.1.1","eslint":"^2.5.3","jest-cli":"^0.10.2","source-map-support":"^0.4.0"},"dependencies":{"lodash":"^4.10.0"},"gitHead":"a9d0677c0ea6833692ba49962926613666cb1514","_id":"s-enum@1.1.3","_shasum":"2d60bb695e4d67f5ee1f75f2e36b5885936136a9","_from":".","_npmVersion":"3.8.5","_nodeVersion":"4.2.1","_npmUser":{"name":"zeroasterisk","email":"alan@zeroasterisk.com"},"dist":{"shasum":"2d60bb695e4d67f5ee1f75f2e36b5885936136a9","tarball":"https://registry.npmjs.org/s-enum/-/s-enum-1.1.3.tgz","integrity":"sha512-jiSZUgIneo39G5ko3kjZ3YslwFDbSi6YZOMgSYitv/3pq2nkg52mHESD4cqvxFydl2r4H3Hiq3cO3T1uH7a8ng==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBbXoqji2M0XBg6keG5m+84gEi2nvoFbFy87o04mYcXwAiEAtKXU7eExOvSQ+hGUMrDvzqoUph+I0mxMYNfIR8wqK3Y="}]},"maintainers":[{"name":"zeroasterisk","email":"alan@zeroasterisk.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/s-enum-1.1.3.tgz_1460490835568_0.8124227449297905"}},"1.1.4":{"name":"s-enum","version":"1.1.4","description":"SEnum = Super Enum Factory","main":"dist/s_enum.cjs.js","jsnext:main":"dist/s_enum.es6.js","scripts":{"build":"build","test":"jest"},"jest":{"unmockedModulePathPatterns":["<rootDir>/node_modules/lodash"]},"repository":{"type":"git","url":"git+https://github.com/zeroasterisk/npm-s-enum.git"},"keywords":["enum","factory"],"author":{"name":"Alan Blount","email":"alan@zeroasterisk.com"},"license":"MIT","bugs":{"url":"https://github.com/zeroasterisk/npm-s-enum/issues"},"homepage":"https://github.com/zeroasterisk/npm-s-enum#readme","devDependencies":{"babel-eslint":"^6.0.0","babel-jest":"^10.0.2","babel-plugin-lodash":"^2.2.2","babel-preset-es2015":"^6.6.0","babel-preset-es2015-rollup":"^1.1.1","eslint":"^2.5.3","jest-cli":"^0.10.2","source-map-support":"^0.4.0"},"dependencies":{"lodash":"^4.10.0"},"gitHead":"a9d0677c0ea6833692ba49962926613666cb1514","_id":"s-enum@1.1.4","_shasum":"895cff0852af36189e4f7befb253655e99e7b97c","_from":".","_npmVersion":"3.8.5","_nodeVersion":"4.2.1","_npmUser":{"name":"zeroasterisk","email":"alan@zeroasterisk.com"},"dist":{"shasum":"895cff0852af36189e4f7befb253655e99e7b97c","tarball":"https://registry.npmjs.org/s-enum/-/s-enum-1.1.4.tgz","integrity":"sha512-M2SIYikeE3JvTv2wvCXc4f7W6XYF5cFK4D8qyU9uKiZT/DWaT46t33Ok2ObFBlTMtn0wDpIa6m0atyieS/nu+Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH77hll6/XzqyflYo8OVW6VW4dBqTxY5GJi1FYB5DqqJAiEA40J53/u7LZg2mQoJ8AQ0rMCdG5juS4gm13yyfz0zjd4="}]},"maintainers":[{"name":"zeroasterisk","email":"alan@zeroasterisk.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/s-enum-1.1.4.tgz_1465920556737_0.9217091405298561"}},"1.1.5":{"name":"s-enum","version":"1.1.5","description":"SEnum = Super Enum Factory","main":"dist/s_enum.cjs.js","jsnext:main":"dist/s_enum.es6.js","scripts":{"build":"build","test":"jest"},"jest":{"unmockedModulePathPatterns":["<rootDir>/node_modules/lodash"]},"repository":{"type":"git","url":"git+https://github.com/zeroasterisk/npm-s-enum.git"},"keywords":["enum","factory"],"author":{"name":"Alan Blount","email":"alan@zeroasterisk.com"},"license":"MIT","bugs":{"url":"https://github.com/zeroasterisk/npm-s-enum/issues"},"homepage":"https://github.com/zeroasterisk/npm-s-enum#readme","devDependencies":{"babel-eslint":"^6.0.0","babel-jest":"^10.0.2","babel-plugin-lodash":"^2.2.2","babel-preset-es2015":"^6.6.0","babel-preset-es2015-rollup":"^1.1.1","eslint":"^2.5.3","jest-cli":"^0.10.2","source-map-support":"^0.4.0"},"dependencies":{"lodash":"^4.10.0"},"gitHead":"dac78fed2bbd6edd098d05ad8189c1c2509b4ae1","_id":"s-enum@1.1.5","_shasum":"7f3b87a709ba83b715ba21ca9ff6de8b525f3ec3","_from":".","_npmVersion":"3.8.5","_nodeVersion":"4.2.1","_npmUser":{"name":"zeroasterisk","email":"alan@zeroasterisk.com"},"dist":{"shasum":"7f3b87a709ba83b715ba21ca9ff6de8b525f3ec3","tarball":"https://registry.npmjs.org/s-enum/-/s-enum-1.1.5.tgz","integrity":"sha512-MIY73nHn9IAHQOJTN/4OeyHtJ5b2GAmb34jhzUksPMfvKSBUoVFDRKSHTuL4DY8Od4EGTAQIaWL8ZoRr/HHYqw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCxtkUyw60YQNZz9KEZkYrjldvuouzIIBjgsb9QsJbqxwIhAKkEw33NJfwS0MdA0A85HerDW0tt2baOFC5+eEUnVkrv"}]},"maintainers":[{"name":"zeroasterisk","email":"alan@zeroasterisk.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/s-enum-1.1.5.tgz_1465921112977_0.02114230254665017"}}},"readme":"# Super Enum Factory: `SEnum(list)`\n\nEnums are great, for reducing a list of values, keys, labels, etc\n\n> In computer programming, an enumerated type (also called enumeration or enum, or factor in the R programming language, and a categorical variable in statistics) is a data type consisting of a set of named values called elements, members or enumerators of the type.\n> https://en.wikipedia.org/wiki/Enumerated_type\n\n> You should always use enums when a variable (especially a method parameter) can only take one out of a small set of possible values. Examples would be things like type constants (contract status: \"permanent\", \"temp\", \"apprentice\"), or flags (\"execute now\", \"defer execution\").\n> http://stackoverflow.com/a/4709224/194105\n\nYou end up with `values` which are smaller, so less goes into your database, and\nless \"over the wire\", from server to client and back.\n\nThe translation from `values` to `labels` is all in very small application code,\ncached on the client.\n\n## Install\n\n```\nnpm install --save s-enum\n```\n\n## Terms\n\n* `key` should be a **camelCase** string selector for any node.\n * if you provide one, we don't do anything to it\n * if you do not provide one, we attempt to translate `label` to camelCase\n* `value` can be **anything**... usually a number or string or function\n * if you don't provide one, we attempt to create a numerical value incrementing\n   from `0`\n* `label` should be a **human readable string**\n * if you don't provide one, we use key\n\n\n## Usage Example: Days of the Week (basics)\n\nFirst you create your enum object... this can happen anywhere\n\n``` js\nvar Days = SEnum([\n  \"Sunday\",\n  \"Monday\",\n  \"Tuesday\",\n  \"Wednesday\",\n  \"Thursday\",\n  \"Friday\",\n  \"Saturday\"\n]);\n\n// now you can access:\nDays.values() === [0, 1, 2, 3, 4, 5, 6];\nDays.keys() === [\"sunday\", \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\"];\nDays.labels() === [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"];\nDays.options() === {0: \"Sunday\", 1: \"Monday\", 2: \"Tuesday\", 3: \"Wednesday\", 4: \"Thursday\", 5: \"Friday\", 6: \"Saturday\"};\n\n// and via aliases on the value\nDays.0.label === \"Sunday\";\nDays.0.key === \"sunday\";\nDays.0.value === 0;\n\n// and via aliases on the key\nDays.sunday.label === \"Sunday\"\nDays.sunday.key === \"sunday\"\nDays.sunday.value === 0;\n\n// and use a get() to return any specific field, from value or key\nDays.get(\"sunday\", \"value\") === 0;\nDays.get(0, \"label\") === \"Sunday\";\nDays.get(\"not-found\", \"value\", \"defaultValue\") === \"defaultValue\";\n```\n\n## Usage Example: Status\n\nFirst you create your enum object... this can happen anywhere, but in this\nexample we are going to think about attaching this to an Object\n(a data model / Collection object).\n\n``` js\nTasks.Statuses = SEnum([\n  { key: \"submitted\", value: 1,  label: \"Submitted\",\n    icon: \"fa fa-check\" },\n  { key: \"accepted\",  value: 2,  label: \"Accepted\",\n    icon: \"fa fa-check-circle\" },\n  { key: \"completed\", value: 31, label: \"All Done Yo\",\n    icon: \"fa fa-check-square\", finished:  true }\n]);\n\n// NOTE in additiion to the basics above, you can get to any field configured\n\nTasks.Statuses.get(\"submitted\", \"icon\") === \"fa fa-check\";\nTasks.Statuses.get(1, \"icon\") === \"fa fa-check\";\nTasks.Statuses.get(31, \"finished\") === true;\nTasks.Statuses.get(1, \"finished\") === undefined;\nTasks.Statuses.get(1, \"finished\", \"defaultValue\") === \"defaultValue\";\n\n// and via aliases on the value\nTasks.Statuses.1.icon === \"fa fa-check\";\nTasks.Statuses.submitted.icon === \"fa fa-check\";\n```\n\n#### Integrating into Meteor (optional)\n\nWhen this was originally written, it was for a [MeteorJS](https://meteor.com) application.\nThe following logic is how you can automatically translate/transform inputs\ninto SEnum values before writing to the database.  You can also validate to\nonly allow these values.\n\nIf you want, you can setup a\n[simple-schema](https://github.com/aldeed/meteor-simple-schema/)\nto only allow values from the SEnum.\n\n``` js\n// allow all values\nallowedValues: Tasks.Statuses.values(),\n// or allow all values AND all keys [1, 2, 31, \"submitted\", \"accepted\", \"completed\"]\nallowedValues: Tasks.Statuses.values().concat(Tasks.Statuses.keys()),\n```\n\nYou can setup a transform, translating all `keys` & `labels` into `values`\n\nIf you want to, you can setup a\n[Mongo.Collection transform](http://docs.meteor.com/#/full/mongo_collection)\nThis will allow a user to pass in any `value` or `key`, and verify that it's got\na valid, `value`; if not it changes to `0`.\n\n``` js\nTasks = new Mongo.Collection('tasks', {\n  transform:  function(doc) {\n    if (_.has(doc, \"status\")) {\n      doc.status = Tasks.Statuses.value(doc.status, 0);\n    }\n    return doc;\n  }\n});\n```\n\nIf you're using autoform/schemas you can setup `autoValue` something like the\nfollowing.\n\nThis will allow a user to pass in any `value` or `key`, and verify that it's got\na valid, `value`; if not it unsets... (you could choose not to unset, and\ninstead get validation errors based on `allowedValues`).\n\n``` js\nstatus: {\n  type: Number,\n  optional: true,\n  autoValue: function() {\n    var autoFormField = this.field(\"status\");\n    if (!autoFormField.isSet) {\n      this.unset();\n      return;\n    }\n    var status = Tasks.Statuses.value(autoFormField.value);\n    if (typeof status === \"undefined\") {\n      this.unset();\n      return;\n    }\n    return status;\n  }\n}\n```\n\nAnd for any template, you can easily translate\n`value` -> `label`\nor any `value` -> any other field...\n\nThis allows some fancy and simple comparable translations.\n\n``` js\nTemplate.Example.helpers({\n\n  // value -> label\n  status: function() {\n    return Tasks.Statuses.label(this.status);\n  },\n\n  // value -> <i> font awesome icon (with default=?)\n  statusIcon: function() {\n    var icon = Tasks.Statuses.get(this.status, \"icon\");\n    if (!icon) {\n      icon = \"fa fa-question\";\n    }\n    return '<i class=\"' + icon '\"></i>';\n  },\n\n  // value -> <span class=\"label {{finished?}}\"><i> text\n  statusLabelAndIcon: function() {\n    var label = Tasks.Statuses.label(this.status, \"Unknown\");\n    var icon = Tasks.Statuses.get(this.status, \"icon\");\n    if (!icon) {\n      icon = \"fa fa-question\";\n    }\n    var finished = Tasks.Statuses.get(this.status, \"finished\");\n    var className = finished ? 'success' : 'default';\n    return '<span class=\"label label-' + className + '\">' +\n      '<i class=\"' + icon '\"></i> ' + label +\n      '</span>';\n  }\n});\n```\n\n## TODO / Roadmap\n\n- [x] Construct support for full nodes, simple `[value, ...]` lists, and `{value: lable, ...}` lists\n- [x] Object helper methods: `keys(), values(), labels()`\n- [x] Object helper methods: `get(), value(), label()`\n- [x] Fully tested\n- [x] README w/ real world usage examples\n- [ ] Meteor ui helper (maybe as extra optional package) `{{SEnum status Tasks.Statuses}}`\n\n\n","maintainers":[{"name":"zeroasterisk","email":"alan@zeroasterisk.com"}],"time":{"modified":"2022-06-26T15:08:28.502Z","created":"2016-04-12T14:26:31.343Z","1.1.0":"2016-04-12T14:26:31.343Z","1.1.1":"2016-04-12T19:47:21.126Z","1.1.2":"2016-04-12T19:51:31.909Z","1.1.3":"2016-04-12T19:53:57.853Z","1.1.4":"2016-06-14T16:09:19.100Z","1.1.5":"2016-06-14T16:18:35.959Z"},"homepage":"https://github.com/zeroasterisk/npm-s-enum#readme","keywords":["enum","factory"],"repository":{"type":"git","url":"git+https://github.com/zeroasterisk/npm-s-enum.git"},"author":{"name":"Alan Blount","email":"alan@zeroasterisk.com"},"bugs":{"url":"https://github.com/zeroasterisk/npm-s-enum/issues"},"license":"MIT","readmeFilename":"README.md"}