npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-cryptostore

v16.0.0

Published

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.2.10. to store data (string, object or array of objects) in local stores or the session store with crypto-js package

Downloads

51

Readme

NgCyptoStore

This library was generated with Angular CLI version 14.2.10. to store data (string, object or array of objects) in local stores or the session store with crypto-js package

Table of Contents

Declaration

...
import { StorageModule } from 'ng-cryptostore';

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    ...
    // ( localStorage | sessionStorage | cookies )
    StorageModule.withConfig({ storageType: "localStorage" })
  ],
  providers: [...],
  bootstrap: [...]
})
export class AppModule { }

Imports and injections

import { StorageService } from 'ng-cryptostore';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

  constructor(private store:StorageService){} // <---- dependency injection (DI)

  ngOnInit(): void {
    this.store.set('fruits',[{name:'fraise',icons:'🍓'},{name:'banana',icons:'🍌'}])
  }
}

All Functions

set(name: string, data: any, secret?: string): Promise<void>;
get(name: string, secret?: string): any;
asyncGet(name: string, secret?: string): Promise<any>;
getEncrypted(name: string): any
remove(name: string): void;
check(name: string): boolean;
getItemLength(name: string, secret?: string): Promise<number>;
clearAll(): void;
crypt(data: any, secret?: string): Promise<any>;
decrypt(scripts: string, secret?: string): Promise<any>;

Usage

(method) set(name: string, data: any, secret?: string): Promise

method 'set' store the data for example :

// store array of objects encrypted
const fruitsArray = [
  { name: "fraise", icons: "🍓" },
  { name: "banana", icons: "🍌" },
];
this.store.set("fruitsArray", fruitsArray);

// store object encrypted
this.store.set("fruit", { name: "orange", icons: "🍊" });

// store string encrypted
this.store.set("strings", "fruits: orange,fraise,banana and ...");

// store numbers encrypted
this.store.set("numbers", 1234567892121);

(method) get(name: string, secret?: string): any

method 'get' read the data for example :

// get fruits array decrypted
console.log(this.store.get("fruitsArray")); //  [{…}, {…}]

// get fruit object decrypted
console.log(this.store.get("fruit")); //  {…}

// get fruit strings decrypted
console.log(this.store.get("strings")); //  fruits: orange,fraise,banana and ...

// get numbers decrypted
console.log(this.store.get("numbers")); //  1234567892121

// in case the item does not exist
console.log(this.store.get("this_item_does_not_exist")); //  ""

(method) asyncGet(name: string, secret?: string): Promise

method 'asyncGet' read the data with promise for example :

// get data decrypted
this.store.asyncGet("fruitsArray").then((res) => {
  console.log(res); // [{…}, {…}]
});

// Or

// get data decrypted
console.log(await this.store.asyncGet("fruitsArray")); // [{…}, {…}]

(method) getEncrypted(name: string): any

method 'getEncrypted' read the data for example :

// get data encrypted
console.log(this.store.getEncrypted("fruitsArray")); // U2FsdGVkX18lKfMIr8dpIGGLy...

(method) check(name: string): boolean

method 'check' check the existence of the key and the value for example :

// check if this item exist, if exist return true
console.log(this.store.check("fruit")); // true or false

(method) remove(name: string): void

method 'remove' remove one item by name for example :

this.store.remove("fruit");

(method) clearAll(): void

method 'clearAll' remove all items for example :

this.store.clearAll();

(method) getItemLength(name: string, secret?: string): Promise

method 'getItemLength' decrypt and get length for example :

console.log(this.store.getItemLength("fruit")); // 21

(method) crypt(data: any, secret?: string): Promise

method 'crypt' return data encrypted for example :

const data = [
  { name: "fraise", icons: "🍓" },
  { name: "banana", icons: "🍌" },
];

console.log(await this.store.crypt(data)); // U2FsdGVkX18lKfMIr8dpIGGLy...

(method) decrypt(scripts: string, secret?: string): Promise

method 'decrypt' return data decrypted for example :

const dataEncrypted = "U2FsdGVkX18lKfMIr8dpIGGLy...";

console.log(await this.store.decrypt(dataEncrypted)); // [{ name: "fraise", icons: "🍓" },{ name: "banana", icons: "🍌"}]

Options

the secret is optional but if you used a custom secret in setItem you need to store it somewhere to use it later in getItem

// set data encrypted with token !secret token @123456
this.store.set(
  "fruits",
  [{ name: "orange", icons: "🍊" }],
  "!secret token @123456"
);

// get data using token "!secret token @123456"

this.store.asyncGet("fruits", "!secret token @123456").then((res) => {
  console.log(res); // [{…}]
});

console.log(this.store.get("fruits", "!secret token @123456")); //  [{…}, {…}]

console.log(this.store.getItemLength("fruit", "!secret token @123456")); // 1