{"id":19299151,"url":"https://github.com/codincat/fluent-object","last_synced_at":"2025-06-10T12:07:18.374Z","repository":{"id":57238968,"uuid":"76237478","full_name":"CodinCat/fluent-object","owner":"CodinCat","description":"Create fluent objects, by the magic of Proxy","archived":false,"fork":false,"pushed_at":"2016-12-12T10:22:28.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-02T10:51:53.176Z","etag":null,"topics":[],"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/CodinCat.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":"2016-12-12T08:34:42.000Z","updated_at":"2016-12-12T10:24:18.000Z","dependencies_parsed_at":"2022-09-05T08:21:41.031Z","dependency_job_id":null,"html_url":"https://github.com/CodinCat/fluent-object","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/CodinCat%2Ffluent-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodinCat%2Ffluent-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodinCat%2Ffluent-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodinCat%2Ffluent-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodinCat","download_url":"https://codeload.github.com/CodinCat/fluent-object/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodinCat%2Ffluent-object/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259072717,"owners_count":22801074,"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-11-09T23:10:19.117Z","updated_at":"2025-06-10T12:07:18.335Z","avatar_url":"https://github.com/CodinCat.png","language":"JavaScript","readme":"# fluent-object\n\nYou should know what will happen:\n\n```js\nconst obj = {}\nobj.a.b.c.d = 'hi'\n```\n\n## Uncaught TypeError: Cannot read property 'b' of undefined\n\nThis simple script can help you to create a `fluent object`\n\n`npm install fluent-object`\n\n```js\nimport createFluentObject from 'fluent-object'\n\nconst obj = createFluentObject()\nobj.a.b.c.d = 'hi'\n```\n\nnow you have an object like this:\n\n```js\nobj = {\n  a: {\n    b: {\n      c: {\n        d: 'hi'\n      }\n    }\n  }\n}\n```\n\nin fact, the `obj` is a [Proxy](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Proxy), and all of its object children (a, b, c) are Proxies.\n\n## API\n\n**`createFluentObject([object[, customCreator])`**\n\n```js\nimport createFluentObject from 'fluent-object'\n\nconst obj1 = createFluentObject({ foo: 'bar' })\nobj1.auto.extend.att = 'hello'\nobj1.another.att = 100\n\n// now obj1 = \n{\n  foo: 'bar',\n  auto: {\n    extend: {\n      att: 'hello'\n    }\n  },\n  another: {\n    att: 100\n  }\n}\n```\n\nnote: the object attributes of your source object will not be converted to proxies.\n\n```js\nconst obj2 = createFluentObject({\n  foo: {\n    bar: 'hihihi'\n  }\n})\n\nobj2.foo.a.b // Cannot read property 'b' of undefined\n\n```\n\n`customCreator` is a function that will be used to create a new extended objects  \n**`customCreator(): object`**\n\n```js\nconst obj3 = createFluentObject({}, () =\u003e {\n  return { foo: 'bar' }\n})\n\nobj3.a.b.c = true\n\n// now obj3 =\n{\n  a: {\n    foo: 'bar',\n    b: {\n      foo: 'bar',\n      c: true\n    }\n  }\n}\n\n// auto attach method\nconst obj4 = createFluentObject({}, () =\u003e {\n  return {\n    sayHi () {\n      console.log('hi')\n    }\n  }\n})\n\nobj4.a.b.sayHi()\n// =\u003e hi\n\n```\n\n### Browser Support\n\nhttps://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Proxy#Browser_compatibility\n\nproxy polyfill for older browsers: https://github.com/GoogleChrome/proxy-polyfill\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodincat%2Ffluent-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodincat%2Ffluent-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodincat%2Ffluent-object/lists"}