{"id":15498776,"url":"https://github.com/jankapunkt/js-class-privacy","last_synced_at":"2026-01-20T15:32:34.782Z","repository":{"id":42923455,"uuid":"244309746","full_name":"jankapunkt/js-class-privacy","owner":"jankapunkt","description":"Create a given ES6 class with private members using Proxy and closures. Keeps class code clean, encourages SRP and DRY.","archived":false,"fork":false,"pushed_at":"2023-01-06T02:36:42.000Z","size":1793,"stargazers_count":3,"open_issues_count":12,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T19:29:02.196Z","etag":null,"topics":["abstract-factory","es6-class","es6-classes","es6-javascript","es6-proxy","factory-method-pattern","javascript","private-members","security"],"latest_commit_sha":null,"homepage":"","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/jankapunkt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://paypal.me/kuesterjan"]}},"created_at":"2020-03-02T07:43:03.000Z","updated_at":"2021-12-20T03:59:53.000Z","dependencies_parsed_at":"2023-02-05T03:31:21.647Z","dependency_job_id":null,"html_url":"https://github.com/jankapunkt/js-class-privacy","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":"jankapunkt/npm-package-template","purl":"pkg:github/jankapunkt/js-class-privacy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankapunkt%2Fjs-class-privacy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankapunkt%2Fjs-class-privacy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankapunkt%2Fjs-class-privacy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankapunkt%2Fjs-class-privacy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jankapunkt","download_url":"https://codeload.github.com/jankapunkt/js-class-privacy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankapunkt%2Fjs-class-privacy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28606142,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T14:45:23.139Z","status":"ssl_error","status_checked_at":"2026-01-20T14:44:16.929Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["abstract-factory","es6-class","es6-classes","es6-javascript","es6-proxy","factory-method-pattern","javascript","private-members","security"],"created_at":"2024-10-02T08:47:37.688Z","updated_at":"2026-01-20T15:32:34.764Z","avatar_url":"https://github.com/jankapunkt.png","language":"JavaScript","funding_links":["https://paypal.me/kuesterjan"],"categories":[],"sub_categories":[],"readme":"# :lock: Javascript Class-Privacy\n\n[![Build Status](https://travis-ci.org/jankapunkt/npm-package-template.svg?branch=master)](https://travis-ci.org/jankapunkt/js-class-privacy)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n![npm bundle size](https://img.shields.io/bundlephobia/min/class-privacy)\n\n\nLean dry no-dep srp :cup: package to create instances from classes with defined private members.\nKeep your classes clean und use this instead to define private properties.\nUses proxies to hide information.\n\n## Installation and basic usage\n\nInstall this package via NPM like\n\n```bash\n$ npm install class-privacy\n```\n\nThe packages exports only one function, that acts similar to an abstract factory.\nYou can pass in a `decide` function to define rules (e.g. whitelist)\nfor members. The created factory can be used to create (proxies to) instances that\ncontain only the public members.\n\n```javascript\nimport createFactory from 'class-privacy'\n\nexport class Person {\n  constructor ({ name, age }) {\n    this.name = name\n    this.age = age\n  }\n\n  greet () {\n    return `Hello, my name is \"${this.name}\". I am ${this.age} years old.`\n  }\n}\n\n// make all functions public, all other members are private \nconst decide = (key, type) =\u003e type === 'function'\n\n// create the factory for private persons \nconst createPrivatePerson = createFactory(Person, { decide })\n\nconst anon = createPrivatePerson({ name: 'John Doe', age: 42 })\nanon.name // undefined\nanon.age // undefined\nanon.greet() // `Hello, my name is \"John Doe\". I am 42 years old.`\n```\n\n### Options\n\nAs shown in the example above, the factory can be created with certain\nconfigurations, defined as `options`:\n\n#### `decide`\n\nA function that is invoked on every access request (proxy `get` trap) \nand receives `key`, `type` and `ClassDefinition` to decide, whether\nthis member should be allowed to be public or kept being private.\n\nSignature:\n\n```javascript\ndecide: (key, type, ClassDefinition) =\u003e Boolean\n```\n\nNon-boolean return values are evaluated as truthy/falsy.\nIf not passed in options, all members are included by default to preserve the original\nstate.\n\n#### `revealIsProxy`\n\nIf this option is set to `true` the `isProxy` property will be added to the\nproxy in order to allow a classification of the Object as proxy.\n\n```javascript\nimport createFactory from 'class-privacy'\n\nexport class Person {\n  constructor ({ name, age }) {\n    this.name = name\n    this.age = age\n  }\n\n  greet () {\n    return `Hello, my name is \"${this.name}\". I am ${this.age} years old.`\n  }\n}\n\nconst createPrivatePerson = createFactory(Person, { revealIsProxy: true })\nconst anon = createPrivatePerson({ name: 'John Doe', age: 42 })\nanon.isProxy // true\n```\n\n#### `referenceClass`\n\nIf this option is set to `true` the `class` property will be added to the\nproxy in order to allow a classification of the instance as proxy to the given \nclass definition.\n\n```javascript\nimport createFactory from 'class-privacy'\n\nexport class Person {\n  constructor ({ name, age }) {\n    this.name = name\n    this.age = age\n  }\n\n  greet () {\n    return `Hello, my name is \"${this.name}\". I am ${this.age} years old.`\n  }\n}\n\nconst createPrivatePerson = createFactory(Person, { referenceClass: true })\nconst anon = createPrivatePerson({ name: 'John Doe', age: 42 })\nanon.class === Person // true\n```\n\n## Code Quality\n\nWe use `standard` as opinionated but zero-config linter.\nYou can run lint in two modes:\n\n##### lint \n \n```bash\n$ npm run lint\n``` \n\n##### lint with auto fixing\n\n```bash\n$ npm run lint:fix\n``` \n\n## Run the tests\n\nWe use mocha and chai with a mostly (but not strict) behavioural style for testing.\nYou can run the tests in three different contexts:\n\n##### Single run\n\n```bash\n$ npm run test\n``` \n\n##### Watch mode\n\n```bash\n$ npm run test:watch\n``` \n\n##### Coverage\n\n```bash\n$ npm run test:coverage\n``` \n\n## Documentation\n\nDocumentation is using jsDoc and is available as [html](docs/index.html) or [markdown](api.md) version.\n\nTo build the documentation in development, you need to run \n\n```bash\n$ npm run docs\n``` \n\n## Build the package\n\nThe package can be build into the `dist` folder using `babel` and the respective script:\n\n```bash\n$ npm run build\n```\n\n\n## License\n\nMIT, see [license file](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjankapunkt%2Fjs-class-privacy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjankapunkt%2Fjs-class-privacy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjankapunkt%2Fjs-class-privacy/lists"}