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

@buttercup/facades

v1.6.0

Published

Archive and Entry facade management for data transfer and application

Downloads

25

Readme

Facades

Editing facades for Buttercup vaults and content

Buttercup Build Status npm version

About

This library contains facade functionality used for editing and applying changes to Buttercup vaults and their contained items. Facades are object representations of Buttercup's instance-based componets like Archive, Group and Entry. Facades can be transferred more easily than class instances and can be consumed using this library.

Usage

This library should be used in conjunction with Buttercup core:

npm install buttercup @buttercup/facades --save
const { Archive } = require("buttercup");
const { consumeArchiveFacade, createArchiveFacade, createEntryFacade } = require("@buttercup/facades");

const archive = new Archive();
const group = archive.createGroup("Test");
const facade = createArchiveFacade(archive);

// Change group title
facade.groups.find(item => item.id === group.id).title = "New Title";

// Add new entry
const entryFacade = createEntryFacade();
entryFacade.parentID = group.id;
entryFacade.fields.find(item => item.property === "title").value = "New Entry";
entryFacade.fields.find(item => item.property === "username").value = "[email protected]";
entryFacade.fields.find(item => item.property === "password").value = "passw0rd";
facade.entries.push(entryFacade);

// Write changes back to archive
consumeArchiveFacade(archive, facade);

You can read about the various facade properties in the API documentation.

Creating new objects

The createEntryFacade function normally takes an Entry instance, but can be used without one to create a new entry. Once created make sure to set parentID to the ID of the parent group. You can override the facade type of new entries by specifying it upon creation: createEntryFacade(null, { type: "website" }).

You can create new groups by using createGroupFacade - passing no group to this method creates a new group facade. You can specify the parent group's ID (defaults to root) as the second parameter to the method. Make sure to set the title property before writing it back.

You can add new properties to entries by using the createFieldDescriptor method:

const entryFacade = createEntryFacade(entry);
const field = createFieldDescriptor(entry, "myProp", "property", "myProp");
field.value = "some new value";
entryFacade.fields.push(field);
consumeEntryFacade(entry, entryFacade);

createFieldDescriptor has the following signature: createFieldDescriptor(entry, title, propertyType, propertyName).

Value types

Facade fields (and therefore Buttercup entry properties) can have specific value types. The default is of course text, but types such as "note", "otp" and "password" can be applied:

const {
    FIELD_VALUE_TYPE_NOTE,
    FIELD_VALUE_TYPE_OTP,
    FIELD_VALUE_TYPE_PASSWORD,
    FIELD_VALUE_TYPE_TEXT
} = require("@buttercup/facades");

const entryFacade = createEntryFacade(entry);
const field = createFieldDescriptor(entry, "My Notes", "property", "My Notes", FIELD_VALUE_TYPE_NOTE);
field.value = "My\nmultiline\nnote!";
entryFacade.fields.push(field);
consumeEntryFacade(entry, entryFacade);

Value types essentially only change how the entry property is rendered whilst viewing the data.

Special facade properties

Properties may be prefixed with an underscore, such as with _history. These properties are created when a facade is generated, but are not processed at the time of consumption.

Important notes regarding usage

Facade consumption is inherently destructive, so be sure that when consuming facades you're applying the correct facade instance to the original class instance. Applying the wrong facade could potentially end up deleting all items (groups and entries) from the original archive instance.