{"id":16419726,"url":"https://github.com/ericls/react-put","last_synced_at":"2025-03-23T07:31:46.606Z","repository":{"id":57342888,"uuid":"79070808","full_name":"ericls/react-put","owner":"ericls","description":"A flexible formatter and i18n interface for React. ","archived":false,"fork":false,"pushed_at":"2017-02-03T19:45:32.000Z","size":15,"stargazers_count":23,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T18:44:59.448Z","etag":null,"topics":["formatter","i18n","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericls.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-16T01:10:34.000Z","updated_at":"2020-06-11T17:53:27.000Z","dependencies_parsed_at":"2022-09-16T03:02:17.401Z","dependency_job_id":null,"html_url":"https://github.com/ericls/react-put","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Freact-put","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Freact-put/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Freact-put/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Freact-put/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericls","download_url":"https://codeload.github.com/ericls/react-put/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245071811,"owners_count":20556352,"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":["formatter","i18n","react"],"created_at":"2024-10-11T07:25:44.143Z","updated_at":"2025-03-23T07:31:46.297Z","avatar_url":"https://github.com/ericls.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-put\n[![Build Status](https://travis-ci.org/ericls/react-put.svg?branch=master)](https://travis-ci.org/ericls/react-put)\n[![codecov](https://codecov.io/gh/ericls/react-put/branch/master/graph/badge.svg)](https://codecov.io/gh/ericls/react-put)\n\n\n\u003e A package that displays things in react components. Suitable for formatting and i18n.\n\n[Interactive Demo](https://runkit.com/ericls/runkit-npm-react-put)\n\nThis package works by injecting a function (by default called `put`) into the props of a a connected react component. The injected function takes a `key` and optional context and returns something else (usually a string).\n\n## Install\n\n```bash\nnpm i --save react-put\n```\n\n## Examples:\n\nThe basic usage:\n```javascript\n// App.js\nimport connectPut from \"react-put\"\n\nclass App extends Component {\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003cp\u003e{this.props.put('hello')}, {this.props.put('welcome', 'username')}\u003c/p\u003e\n        \u003cp\u003e{this.props.put('haveApple', 'username', 3)}\u003c/p\u003e\n        \u003cp\u003e{this.props.put('testKey')}\u003c/p\u003e\n      \u003c/div\u003e\n    );\n  }\n}\nconst options = {\n  dictionary: {\n    hello: '你好',\n    welcome: name =\u003e `欢迎${name}`,\n    haveApple: (name, amount) =\u003e `${name} has ${amount} ${amount === 1 ? 'apple' : 'apples'}`,\n  },\n  mapPropToDictionary: props =\u003e props, // You can do something wild with this option\n};\nexport default connectPut(options)(App);\n\n// test.js\nimport App from './App';\n\n...\n  render() {\n    return \u003cApp testKey='someValue' /\u003e\n  }\n...\n\n// renders:\n\u003cdiv\u003e\n  \u003cp\u003e你好, 欢迎username\u003c/p\u003e\n  \u003cp\u003eusername has 3 apples\u003c/p\u003e\n  \u003cp\u003esomeValue\u003c/p\u003e\n\u003c/div\u003e\n\n\n```\n\nHere's an example of the usage with redux managed props:\n```javascript\nclass App extends Component {\n  constructor(props) {\n    super(props);\n    this.changeLanguage = () =\u003e {\n      this.props.dispatch({ type: 'SET_DICT', dictionary: {...} }); // Assume SET_DICT is received by dictionary reducer\n    };\n  }\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003cp\u003e{this.props.put('hello')}, {this.props.put('welcome', 'username')}\u003c/p\u003e\n        \u003cp\u003e{this.props.put('haveApple', 'username', 3)}\u003c/p\u003e\n        \u003cp\u003e{this.props.put('testKey')}\u003c/p\u003e\n        \u003cbutton onClick={this.changeLanguage}\u003eChange Language\u003c/button\u003e\n      \u003c/div\u003e\n    );\n  }\n}\nconst options = {\n  mapPropToDictionary: props =\u003e Object.assign({}, props.dictionary),\n};\nconst mapStateToProps = state =\u003e Object.assign({}, { dictionary: state.dictionary });\nConnectedApp = connectPut(options)(App);\nConnectedApp = connect(mapStateToProps)(ConnectedApp);\n```\n\n## Guide:\n\nThis package exposes a single function `connectPut` and is the default export of the package.\n\n### connectPut():\n\n```javascript\ntype Options = {\n  dictionary?: Object,\n  mapPropToDictionary?: (props: Object) =\u003e Object,\n  putFunctionName?: string,\n  notFound?: (key: string) =\u003e any\n}\nconnectPut(options: Options)(Component) =\u003e Component\n```\n\n\n#### Options:\n\nThere are 4 optional keys in the options.\n\n| key  | description |\n| ------------- | ------------- |\n| dictionary  | An object directly used by the injected function  |\n| mapPropToDictionary  | A function that takes `props` of a component and returns an object that updates `dictionary`  |\n| notFound  | A function that takes `key`, if (!(key in dictionary)), and returns something to display. (Defaults to key =\u003e \\`$$${key}\\`)  |\n| putFunctionName  | A string that specifies the injected prop name. (Defaults to `put`)  |\n\n\n### put():\n\nThe connected component will have a new props, which by default is called `put`.\n\n```javascript\nput(key, ...context) =\u003e any\n```\n\nThis function looks up the `key` in dictionary and returns something to return accordingly.\n\nIf the value of the `key` is a string, a string is returned. If the value is a function, the function is called with `...context` and returns.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericls%2Freact-put","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericls%2Freact-put","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericls%2Freact-put/lists"}