Git Product home page Git Product logo

library-tools's Introduction

@beaker/library-tools

Utility library to manage Beaker's library of dats.

Library folder and library.json

Beaker manages a /library folder in the user's private hyperdrive that contains mounts to all saved dats. The archives are sorted into folders according to their "Primary Type" (see getPrimaryType()). An example folder hierarchy:

/library/modules
/library/people
/library/templates
/library/themes
/library/websites
/library/library.json

The library.json file is the primary record of the "saved dats." It lists saved dats along with additional configuration. Here is an example:

{
  "type": "beakerbrowser.com/library",
  "dats": [
    {
      "key": "9892414902579ba93ae62e63d5041b69b137f2aa9e86a4e2bc1bcef70ab6d569",
      "isHosting": true,
      "visibility": "public",
      "savedAt": "2019-08-26T15:02:03.623Z"
    },
    {
      "key": "206bf21c61a8c65e3fb1463d6d9b8231dc2726e795009139747a9152f47bb8f7",
      "isHosting": true,
      "visibility": "unlisted",
      "savedAt": "2019-08-26T15:02:03.623Z"
    }
  ]
}

The json-schema for library.json can be found here.

"Categories"

Dat archives provide a type field in their manifests. The "category" is a shortname mapping to those full types.

If multiple types are set on a dat, the first known type is used to determine the category.

The "website" category is catchall for dats with an unknown type.

API

typeToCategory(type, usePlural=false)

Provides the category for a given manifest's full type value.

libTools.typeToCategory('unwalled.garden/person', false)
// => 'person'
libTools.typeToCategory('unwalled.garden/person', true)
// => 'people'

categoryToType(category)

Provides the full type for a given category. Can use the plural or singular.

libTools.categoryToType('person')
// => 'unwalled.garden/person'
libTools.categoryToType('people')
// => 'unwalled.garden/person'

getCategoriesArray(usePlural=false)

Gives an array of the categories.

libTools.getCategoriesArray(false)
// => ['module', 'person', 'template', 'website']
libTools.getCategoriesArray(true)
// => ['modules', 'people', 'templates', 'websites']

getCategoriesMap(usePlural=false)

Gives a map of the categories to their fully-qualified types.

libTools.getCategoriesMap(false)
/* => {
  module: 'unwalled.garden/module',
  person: 'unwalled.garden/person',
  template: 'unwalled.garden/template',
  website: undefined
} */
libTools.getCategoriesMap(true)
/* => {
  modules: 'unwalled.garden/module',
  people: 'unwalled.garden/person',
  templates: 'unwalled.garden/template',
  websites: undefined
} */

categoryToPlural(category)

Convert a category to its plural.

libTools.categoryToPlural('person')
// => 'people'

categoryToSingular(category)

Convert a category to its singular.

libTools.categoryToSingular('people')
// => 'person'

getFAIcon(category)

Gets the Font Awesome icon for a given category.

libTools.getFAIcon('module')
// => 'fas fa-cube'
libTools.getFAIcon('person')
// => 'far fa-user'
libTools.getFAIcon('template')
// => 'fas fa-pencil-ruler'
libTools.getFAIcon('theme')
// => 'fas fa-drafting-compass'

library-tools's People

Contributors

pfrazee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.