{"id":14982067,"url":"https://github.com/gulpjs/value-or-function","last_synced_at":"2025-10-19T11:31:26.468Z","repository":{"id":4825875,"uuid":"48140881","full_name":"gulpjs/value-or-function","owner":"gulpjs","description":"Normalize a value or function, applying extra args to the function","archived":false,"fork":false,"pushed_at":"2023-03-14T00:13:40.000Z","size":31,"stargazers_count":11,"open_issues_count":0,"forks_count":9,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-29T15:14:45.008Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gulpjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-12-16T23:24:57.000Z","updated_at":"2023-12-10T14:37:41.000Z","dependencies_parsed_at":"2023-07-05T17:15:24.957Z","dependency_job_id":null,"html_url":"https://github.com/gulpjs/value-or-function","commit_stats":{"total_commits":30,"total_committers":7,"mean_commits":4.285714285714286,"dds":0.4666666666666667,"last_synced_commit":"314d3d0c2151846517c89616e690dd50815d81b9"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fvalue-or-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fvalue-or-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fvalue-or-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fvalue-or-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gulpjs","download_url":"https://codeload.github.com/gulpjs/value-or-function/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237116971,"owners_count":19258335,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T14:04:43.813Z","updated_at":"2025-10-19T11:31:21.427Z","avatar_url":"https://github.com/gulpjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://gulpjs.com\"\u003e\n    \u003cimg height=\"257\" width=\"114\" src=\"https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n# value-or-function\n\n[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]\n\nNormalize a value or function, applying extra args to the function\n\n## Example\n\n```js\nvar normalize = require('value-or-function');\n\n// Values matching type are returned\nvar isEnabled = normalize('boolean', true);\n// isEnabled === true\n\n// Values not matching type return undefined\nvar isEnabled = normalize('boolean', 1);\n// isEnabled === undefined\n\n// Functions are called\nvar isEnabled = normalize('boolean', function () {\n  return false;\n});\n// isEnabled === false\n\n// Extra arguments are applied to function\nvar count = normalize(\n  'number',\n  function (a, b) {\n    return a + b;\n  },\n  1,\n  2\n);\n// count === 3\n\n// Supply the function with context\nvar context = { c: 3 };\nvar count = normalize.call(\n  context,\n  'number',\n  function (a, b) {\n    return a + b + this.c;\n  },\n  1,\n  2\n);\n// count === 6\n\n// Values one of multiple types are returned\nvar isEnabled = normalize(['string', 'boolean'], true);\n// isEnabled === true\n\n// Provide a function as first argument to do custom coercion\nvar now = new Date();\nvar enabledSince = normalize(function (value) {\n  if (value.constructor === Date) {\n    return value;\n  }\n}, now);\n// enabledSince === now\n\n// Convenience methods are available for the built-in types\nvar result = normalize.object({});\nvar result = normalize.number(1);\nvar result = normalize.string('');\nvar result = normalize.symbol(Symbol());\nvar result = normalize.boolean(true);\nvar result = normalize.function(function () {});\nvar result = normalize.date(new Date());\n```\n\n## API\n\n### `normalize(coercer, value[, ...appliedArguments])`\n\nTakes a coercer function `coercer` to transform `value` to the desired type.\nAlso optionally takes any extra arguments to apply to `value` if `value` is a function.\n\nIf the return value of `coercer(value)` is not `null` or `undefined`, that value is returned.\nOtherwise, if `value` is a function, that function is called with any extra arguments\nsupplied to `normalize`, and its return value is passed through the coercer.\n\nIf `coercer` is a string, it must be one of the built-in types (see below)\nand the appropriate default coercer is invoked, optionally first reducing `value`\nto a primitive type with `.valueOf()` if it is an Object.\n\nIf `coercer` is an array, each element is tried until one returns something other\nthan `null` or `undefined`, or it results in `undefined` if all of the elements yield `null` or `undefined`.\n\n#### `normalize.object(value[, ...appliedArguments])`\n\nConvenience method for `normalize('object', ...)`.\n\n#### `normalize.number(value[, ...appliedArguments])`\n\nConvenience method for `normalize('number', ...)`.\n\n#### `normalize.string(value[, ...appliedArguments])`\n\nConvenience method for `normalize('string', ...)`.\n\n#### `normalize.symbol(value[, ...appliedArguments])`\n\nConvenience method for `normalize('symbol', ...)`.\n\n#### `normalize.boolean(value[, ...appliedArguments])`\n\nConvenience method for `normalize('boolean', ...)`.\n\n#### `normalize.function(value[, ...appliedArguments])`\n\nConvenience method for `normalize('function', ...)`.\n\n#### `normalize.date(value[, ...appliedArguments])`\n\nConvenience method for `normalize('date', ...)`.\n\n## License\n\nMIT\n\n\u003c!-- prettier-ignore-start --\u003e\n[downloads-image]: https://img.shields.io/npm/dm/value-or-function.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/value-or-function\n[npm-image]: https://img.shields.io/npm/v/value-or-function.svg?style=flat-square\n\n[ci-url]: https://github.com/gulpjs/value-or-function/actions?query=workflow:dev\n[ci-image]: https://img.shields.io/github/actions/workflow/status/gulpjs/value-or-function/dev.yml?branch=master\u0026style=flat-square\n\n[coveralls-url]: https://coveralls.io/r/gulpjs/value-or-function\n[coveralls-image]: https://img.shields.io/coveralls/gulpjs/value-or-function/master.svg?style=flat-square\n\u003c!-- prettier-ignore-end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgulpjs%2Fvalue-or-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgulpjs%2Fvalue-or-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgulpjs%2Fvalue-or-function/lists"}