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

packrup

v0.1.2

Published

Node Schema.org for Simple and Automated Google Rich Results

Downloads

66,844

Readme

Background

The zhead package provides a flat-object style API for HTML <meta> tags, to make this happen we need to pack and unpack arrays and strings to a flat object.

For example, the following object:

{
  "viewport": {
    "content": {
      "width": "device-width",
      "initial-scale": "1"
    }
  }
}

Can be packed to the below (and vice versa):

<meta name="viewport" content="width=device-width, initial-scale=1">

For an example see useSeoMeta.

Features

  • Pack arrays, objects and strings to a flat object
  • Handles duplicates with key
  • Supports nested key selections with dot.notation
  • 🌳 Composable, tree-shakable and tiny (< 1kb, see export-size-report)

Help Wanted

These utils were meant to be fully typed, but I struggled with the implementation. If you want a fun TypeScript challenge then please open a PR :).

Installation

npm install --save-dev packrup

# Using yarn
yarn add --dev packrup

API

packArray

Arguments

  • input - array

    The array to pack

  • options - { key: string | string[], value: string | string[] }

    The options to use to resolve the key and value. By default, will choose first 2 keys of an object.

import { packArray } from 'packrup'

packArray([
  { 'http-equiv': 'content-security-policy', 'content': 'content-src none' }
])

// {
//    'content-security-policy': 'content-src none',
// }

packObject

Arguments

  • input - object

    The record to pack.

  • options - { key: string | string[], value: string | string[] }

    The options to use to resolve the key and value. By default, will choose first 2 keys of an object.

import { packObject } from 'packrup'

packObject({
  image: {
    src: {
      '1x': 'https://example.com/image.png',
      '2x': 'https://example.com/[email protected]'
    },
    alt: 'Example Image'
  },
}, {
  key: 'image.src.1x',
  value: 'image.alt'
})

// {
//   "https://example.com/image.png": "Example Image",
// }

packString

import { packString } from 'packrup'

const head = packString('src="https://example.com/image.jpg" width="800" height="600"')
// {
//   "height": "600",
//   "src": "https://example.com/image.jpg",
//   "width": "800",
// }

unpackToArray

Arguments

  • input - array

    The array to pack

  • options - { key: string | string[], value: string | string[] }

    The options to use to resolve the key and value. By default, will choose first 2 keys of an object.

import { unpackToArray } from 'packrup'

unpackToArray({
  'content-security-policy': 'content-src none',
}, { key: 'http-equiv', value: 'content' })

unpackToString

Arguments

  • input - object

    The record to unpack to a string.

  • options

export interface TransformValueOptions {
  entrySeparator?: string
  keyValueSeparator?: string
  wrapValue?: string
  resolve?: (ctx: { key: string, value: unknown }) => string | void
}
import { unpackToString } from 'packrup'

unpackToString({
  'noindex': true,
  'nofollow': true,
  'max-snippet': 20,
  'maxi-image-preview': 'large',
}, {
  resolve({ key, value }) {
    if (typeof value === 'boolean')
      return `${key}`
  },
  keyValueSeparator: ':',
  entrySeparator: ', ',
})

// "noindex, nofollow, max-snippet:20, maxi-image-preview:large"

Sponsors

License

MIT License © 2022-PRESENT Harlan Wilton