{"id":28299445,"url":"https://github.com/mikaak/angular-safeguard","last_synced_at":"2025-07-07T06:06:30.472Z","repository":{"id":4101878,"uuid":"51916868","full_name":"MikaAK/angular-safeguard","owner":"MikaAK","description":"Wrapper around cookies/sessionStorage/localStorage for angular2. If all are unavailable will use an in memory storage.","archived":false,"fork":false,"pushed_at":"2023-02-27T15:28:57.000Z","size":3175,"stargazers_count":77,"open_issues_count":21,"forks_count":17,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-09T13:39:57.151Z","etag":null,"topics":["angular2","cookies","localstorage","sessionstorage"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/MikaAK.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,"governance":null}},"created_at":"2016-02-17T11:12:55.000Z","updated_at":"2024-10-11T18:01:42.000Z","dependencies_parsed_at":"2023-07-06T01:55:16.816Z","dependency_job_id":null,"html_url":"https://github.com/MikaAK/angular-safeguard","commit_stats":{"total_commits":124,"total_committers":14,"mean_commits":8.857142857142858,"dds":0.6370967741935484,"last_synced_commit":"de7297093f17b56c4c0a9f09490ea00f44efcec7"},"previous_names":["mikaak/angular2-locker"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/MikaAK/angular-safeguard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikaAK%2Fangular-safeguard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikaAK%2Fangular-safeguard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikaAK%2Fangular-safeguard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikaAK%2Fangular-safeguard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MikaAK","download_url":"https://codeload.github.com/MikaAK/angular-safeguard/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikaAK%2Fangular-safeguard/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260437630,"owners_count":23009190,"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":["angular2","cookies","localstorage","sessionstorage"],"created_at":"2025-05-23T10:12:44.571Z","updated_at":"2025-07-07T06:06:30.439Z","avatar_url":"https://github.com/MikaAK.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"angular-safeguard\n=====\n[![Build Status](https://travis-ci.org/MikaAK/angular-safeguard.svg?branch=master)](https://travis-ci.org/MikaAK/angular-safeguard)\n\n[![Code Climate](https://codeclimate.com/github/MikaAK/angular2-locker/badges/gpa.svg)](https://codeclimate.com/github/MikaAK/angular2-locker)\n\n***Note: This library was renamed from angular2-locker to angular-safeguard***\n\nWrapper around sessionStorage, localStorage and cookies for angular. If both are unavailable will use an in memory storage.\n\nExpiry is also implemented for all drivers not just cookies\n\n***Breaking Changes in 2.0:***\n\u003e With 2.0 this library supports AoT. As a result there was two options, one to create a\n\u003e storage type for each different storage, and two to change `set/get` and other methods\n\u003e to explicitly use a driver.\n\u003e The latter means we can still provide in-memory fallback without\n\u003e the hassle of you writing conditions everywhere.\n\u003e All methods on locker now have an extra param for storage type such as `get(DRIVERS.SESSION, 'key')`\n\n## Getting Started\n```bash\n$ npm i --save angular-safeguard\n```\n\n```typescript\nimport {NgModule} from '@angular/core'\nimport {LockerModule, Locker, DRIVERS} from 'angular-safeguard'\n\n@Component({\n  selector: 'app',\n  template: `...`\n})\nclass App {\n  constructor(locker: Locker) {\n    locker.set(DRIVERS.SESSION, 'something', value)\n  }\n}\n\n@NgModule({\n  imports: [LockerModule],\n  declarations: [App],\n  bootstrap: [App]\n})\nclass AppModule {\n  constructor(private locker: Locker) {}\n}\n```\n\n### With Custom Config\n```typescript\nimport {LockerModule, LockerConfig, DRIVERS} from 'angular-safeguard'\n\n// to set a single driver\nconst lockerConfig = {\n  driverNamespace: 'nameSpace',\n  driverFallback: DRIVERS.MEMORY,\n  namespaceSeperator: '-'\n}\n\n// to set fallback drivers in order of preference, pass in an Array of Driver\nconst lockerConfig = {\n  driverNamespace: 'nameSpace',\n  driverFallback: [DRIVERS.LOCAL, DRIVERS.SESSION, DRIVERS.COOKIE],\n  namespaceSeperator: '-'\n}\n\n@NgModule({\n  imports: [LockerModule.withConfig(lockerConfig)]\n  ...\n})\nclass SomeModule {\n\n}\n```\n\n## Methods\n#### `get`\n`locker.get(DRIVERS.SESSION, 'myKey')`\n\n#### `set`\n```typescript\nlocker.set(DRIVERS.SESSION, 'myKey', 'value')\nlocker.set(DRIVERS.SESSION, 'myKey', {object: 'value'})\n\nconst expiry = new Date()\n\nexpiry.setHours(expiry.getHours() + 1)\n\nlocker.set(DRIVERS.SESSION, 'myKey', 'value', {expiry}) // will work with every driver type\n\n// You can also use set to pass options for cookies like maxAge and such\n```\n\n#### `key`\n```typescript\nlocker.set(DRIVERS.COOKIES, 'key', 'value')\n\nlocker.key(DRIVERS.COOKIES, 0) // 'key'\n```\n\n#### `has`\n`locker.has(DRIVERS.LOCAL, 'key')`\n\n#### `setNamespace`\n```typescript\nlocker.setNamespace('myName')\nlocker.setNamespace() // Resets to lockerConfig default\n```\n\n#### `setSeparator`\n\n```typescript\nlocker.setSeparator('myName')\nlocker.setSeparator() // Resets to lockerConfig default\n```\n\n#### `remove`\n`locker.remove(DRIVERS.SESSION, 'key')`\n\n#### `clear`\n`locker.clear(DRIVERS.SESSION)`\n\n## Static Methods\n#### `DRIVERS`\n\nThese are the types of drivers available. If you try to set it to a (single) driver that is unsupported it will fallback to the memory driver.  To set fallback drivers, pass in an Array of drivers in the order or preference:\n\nAgain, if every driver in Array is unsupported, it will fall back to memory driver.\n\nTypes are available from `import {DRIVERS} from 'angular-safeguard'`\n\n- `DRIVERS.SESSION` - Session Cache\n- `DRIVERS.LOCAL` - Local Storage\n- `DRIVERS.MEMORY` - Memory Storage\n- `DRIVERS.COOKIE` - Cookies\n\n\n## FAQ\n\n**Why is my data getting set to {data: myDataHere} instead of just myDataHere?**:\nangular-safeguard provides expiry on more than just cookies, to do this it's necessary to create a bit of a more complex\nobject so we can store expiry and more\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikaak%2Fangular-safeguard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikaak%2Fangular-safeguard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikaak%2Fangular-safeguard/lists"}