{"id":15067469,"url":"https://github.com/yusinto/ld-vue","last_synced_at":"2025-07-03T18:36:14.457Z","repository":{"id":57289845,"uuid":"148723075","full_name":"yusinto/ld-vue","owner":"yusinto","description":"A library to integrate Launch Darkly with Vue","archived":false,"fork":false,"pushed_at":"2018-09-26T08:56:49.000Z","size":547,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T13:04:44.043Z","etag":null,"topics":["darkly","feature","feature-flag","feature-flags","flags","integration","js","launch","launchdarkly","ld","ld-vue","ldclient","ldclient-js","targeting","toggle","vue","vue-components","vue2","vuejs","vuejs2"],"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/yusinto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-14T02:13:30.000Z","updated_at":"2021-02-12T16:07:02.000Z","dependencies_parsed_at":"2022-08-25T04:21:56.033Z","dependency_job_id":null,"html_url":"https://github.com/yusinto/ld-vue","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/yusinto%2Fld-vue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusinto%2Fld-vue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusinto%2Fld-vue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusinto%2Fld-vue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yusinto","download_url":"https://codeload.github.com/yusinto/ld-vue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248233936,"owners_count":21069493,"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":["darkly","feature","feature-flag","feature-flags","flags","integration","js","launch","launchdarkly","ld","ld-vue","ldclient","ldclient-js","targeting","toggle","vue","vue-components","vue2","vuejs","vuejs2"],"created_at":"2024-09-25T01:24:19.527Z","updated_at":"2025-04-10T14:22:32.485Z","avatar_url":"https://github.com/yusinto.png","language":"JavaScript","funding_links":[],"categories":["Open Source"],"sub_categories":[],"readme":"# ld-vue\n\n[![npm version](https://img.shields.io/npm/v/ld-vue.svg?style=flat-square)](https://www.npmjs.com/package/ld-vue) [![npm downloads](https://img.shields.io/npm/dm/ld-vue.svg?style=flat-square)](https://www.npmjs.com/package/ld-vue) [![npm](https://img.shields.io/npm/dt/ld-vue.svg?style=flat-square)](https://www.npmjs.com/package/ld-vue) [![npm](https://img.shields.io/npm/l/ld-vue.svg?style=flat-square)](https://www.npmjs.com/package/ld-vue)\n\n\u003e **Integrate Launch darkly with Vue in seconds** :tada:\n\nWhy this package?\n* Easy and fast to use. Two steps to get Launch Darkly feature flags into your Vue app.\n* Supports subscription out of the box. You get live changes on the client as you toggle features.\n* You automatically get camelCased keys as opposed to the default kebab-cased.\n\n## Installation\n\nyarn add ld-vue\n\n## Quickstart\n\n1. Use the `withFlagProvider` mixin in your root App:\n\n    ##### App.vue\n    ```js\n    \u003cscript\u003e\n    import { withFlagProvider } from 'ld-vue'\n    \n    export default {\n      mixins: [withFlagProvider({ clientSideId: 'your-client-side-id' })],\n    }\n    \u003c/script\u003e\n    ```\n\n2. Use the `withFlags` mixin in your Vue component to get them via props:\n\n    ```js\n    \u003ctemplate\u003e\n      \u003cdiv\u003e\n        \u003c!-- this.flags is injected by withFlags --\u003e\n        {{this.flags.devTestFlag ? 'Flag on' : 'Flag off'}}\n      \u003c/div\u003e\n    \u003c/template\u003e\n    \u003cscript\u003e\n    import { withFlags } from 'ld-vue'\n    \n    export default {\n      mixins: [withFlags],\n    }\n    \u003c/script\u003e\n    ```\n\nThat's it!\n\n## API\n### withFlagProvider({clientSideId, user, options})\nThis is a function which accepts a config object with the above properties. Only `clientSideId` is\nmandatory. Returns a mixin which a Vue instance can use like a normal mixin. Use this mixin in your\nroot App.vue instance to initialise ld-vue. \n\nExample usage with class components:\n\n##### App.vue\n```js\n\u003cscript\u003e\nimport Component, { mixins } from 'vue-class-component'\nimport { withFlagProvider } from 'ld-vue'\n\n@Component\nexport default class App extends mixins(withFlagProvider({clientSideId: 'your-client-side-id'})) {}\n\u003c/script\u003e\n```\n\nThe `user` property is optional. You can initialise the sdk with a custom user by specifying one. \nThis must be an object containing at least a \"key\" property. If you don't specify a user object, \nld-vue will create a default one that looks like this:\n\n```js\nconst defaultUser = {\n  key: uuid.v4(), // random guid\n  ip: ip.address(),\n  custom: {\n    browser: userAgentParser.getResult().browser.name,\n    device\n  }\n};\n```\n\nFor more info on the user object, see [here](http://docs.launchdarkly.com/docs/js-sdk-reference#section-users).\n\nThe `options` property is optional. It can be used to pass in extra options such as \n[Bootstrapping](https://github.com/launchdarkly/js-client#bootstrapping).\n\nFor example:\n\n```javascript\nwithFlagProvider({\n    clientSideId,\n    options: {\n      bootstrap: 'localStorage',\n    },\n});\n```\n\n### withFlags\nThis is a mixin which injects all your flags to the specified component via props. Your flags will be available\nas camelCased properties under `this.flags`. For example with class components:\n\n```js\n\u003ctemplate\u003e\n  \u003cdiv\u003e\n    \u003c!-- Look ma feature flags! --\u003e\n    {{this.flags.devTestFlag ? 'Flag on' : 'Flag off'}}\n  \u003c/div\u003e\n\u003c/template\u003e\n\u003cscript\u003e\nimport Component, { mixins } from 'vue-class-component'\nimport { withFlags } from 'ld-vue'\n\n@Component\nexport default class Home extends mixins(withFlags) {}\n\u003c/script\u003e\n```\n\n### ldClient\nInternally ld-vue initialises the ldclient-js sdk and stores a reference to the resultant ldClient object in memory.\nYou can use this object to access the [official sdk methods](https://github.com/launchdarkly/js-client) directly. \nFor example, you can do things like:\n\n```js\n\u003cscript\u003e\nimport Vue from 'vue'\nimport Component from 'vue-class-component'\nimport {ldClient} from 'ld-vue';\n\n@Component\nexport default class Home extends Vue {\n  mounted() {\n    ldClient.track('home page loaded');\n  }\n}\n\u003c/script\u003e\n```\n\n## Example\nCheck the [example](https://github.com/yusinto/ld-vue/tree/master/example) for a standard vue cli app with feature flags.\nRemember to enter your client side sdk in the [root app file](https://github.com/yusinto/ld-vue/blob/master/example/src/App.vue)\nand create a test flag called `dev-test-flag` before running the example!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusinto%2Fld-vue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyusinto%2Fld-vue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusinto%2Fld-vue/lists"}