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

@slicemachine/core

v1.1.19

Published

Primitive operations and data models for the Slicemachine world.

Downloads

10,691

Readme

Slice Machine Core

Primitive operations and data models for the Slicemachine world.

Structure

The core is structured in sub-packages that can be used and imported independently. Although most of the operations it provides are filesystem based, you should be able to import Models and utilities in browser-based environments.

Node-Utils

Query and parse Slicemachine data in the Filesystem

Framework

Some parts of Slicemachine are framework dependent. Use autodetectFramework to get what's identified in your package.json.

import { autodetectFramework } from "@slicemachine/core/build/node-utils";

(async () => {
  const framework = autodetectFramework("." /* project cwd */);
})();

Manifest

Slicemachine projects rely on an sm.json file to configure the behaviour of the plugin (slice-machine-ui mostly).

import * as Manifest from "@slicemachine/core/build/node-utils/manifest";
import { DEFAULT_BASE } from "@slicemachine/core/build/consts";

(async () => {
  const cwd = "./";

  // creates a manifest at path `./sm.json`
  createManifest(cwd, { apiEndpoint: "https://my-project.prismic.io/api/v2" });

  // my-project
  const maybeRepoName = maybeRepoNameFromSMFile(cwd, DEFAULT_BASE);

  patchManifest(cwd, { storybook: `https://${maybeRepoName}.vercel.app` });

  const { exists, content } = retrieveManifest(cwd);

  console.log({ exists, content }); // true, { apiEndpoint, storybook }
})();

Paths

Resolve paths in the context of a Slicemachine project.

Pkg

Work with package.json files

import {
  retrieveJsonPackage,
  patchJsonPackage,
} from "@slicemachine/core/build/node-utils";

(async () => {
  const cwd = "./";
  patchJsonPackage(cwd, { name: "new-name" });
  const { exists, content } = retrieveJsonPackage(cwd);
})();

Libraries (wip)

An essential data model in Slicemachine is Library: a set of components that hold code, Prismic Slice model, screenshots and mocks.

Once registered, retrieve them from the Filesystem

import { libraries } from "@slicemachine/core/build/libraries";

(async () => {
  const cwd = "./";
  const libs = [/* local */ "~/slices", /* in node_modules */ "shared-lib"];

  const myLibs = libraries(cwd, libs);
  /*
        [
            name: string,
            path: string,
            isLocal: boolean,
            components: [{
                from: string,
                href: string,
                pathToSlice: string,
                infos: ComponentInfo,
                model: SliceAsObject,
                migrated: boolean,
            }]
        ]

    */
})();

Models

Types (+ helpers) of Slicemachine data models

Prismic

Helpers to interact with Prismic and Prismic Shared Config object (~/.prismic)

Utils (expanding)

Various helpers to deal with Slicemachine specifics

import { pascalize, snakelize } from "@slicemachine/core/build/utils";

(async () => {
  const camelName = "camelName";

  const componentName = pascalize(camelName); // CamelName
  const prismicId = snakelize(camelName); // camel_name
})();