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

@igor.dvlpr/astro-saferesource

v1.0.1

Published

๐ŸŽ Adds CSP-compliant inline scripts and styles to Astro! ๐ŸŽ 

Downloads

68

Readme

๐Ÿ“ƒ Table of contents

๐Ÿ•ต๐Ÿผ Usage

Install it by executing:

npm i -D "@igor.dvlpr/astro-saferesource"

In order to use it, all you need to do is wrap your existing inline script or style tags with the <SafeResource> component, i.e.:

before.astro

<script is:inline>
  console.log('Hello World')
</script>

after.astro

---
import SafeResource from '@igor.dvlpr/astro-saferesource'
---

<SafeResource>
  <script is:inline> // <-- do not forget to add is:inline, if not present
    console.log('Hello World')
  </script>
</SafeResource>

and the component will generate the following output:

after.html

<!-- other page markup -->

<script integrity="sha256-xhIA8fkWcujZdN5EjKW355zTO9eHOZu4D+SzAE4Qqik=">
  console.log('Hello World')
</script>

<!-- other page markup -->

[!NOTE] The component outputs a SHA-256 hash.

[!CAUTION] Do NOT forget to add is:inline to the element or else Astro will remove it from the <SafeResource> component in order to optimize it.

[!TIP] The component will log the page, type of resource (script/style) and the generated hashes in the console of the IDE.


โœจ Examples

example.astro

---
import SafeResource from '@igor.dvlpr/astro-saferesource'
import Layout from '../layouts/Layout.astro'
---

<Layout title="Welcome to Astro">
  <main style="color: wheat;">
    <SafeResource>
      <script is:inline>
        document.addEventListener('DOMContentLoaded', () => {
          const easyNav = document.getElementById('easy-nav')
          const easyShow = easyNav.getAttribute('data-show')

          if (
            easyShow === 'whenNeeded' &&
            document.documentElement.scrollHeight > window.innerHeight
          ) {
            easyNav.className = 'show'
          }
        })
      </script>
    </SafeResource>

    <SafeResource>
      <style is:inline>
        .eren-jaeger {
          color: red;
        }
      </style>
    </SafeResource>
  </main>
</Layout>

๐Ÿ“ Changelog

๐Ÿ“‘ The changelog is available here: CHANGELOG.md.


๐Ÿชช License

Licensed under the MIT license which is available here, MIT license.


๐Ÿงฌ Related

@igor.dvlpr/astro-post-excerpt

โญ An Astro component that renders post excerpts for your Astro blog - directly from your Markdown and MDX files. Astro v2+ collections are supported as well! ๐Ÿ’Ž

@igor.dvlpr/astro-easynav-button

๐Ÿงญ Add an easy-to-use navigational button (jump to top/bottom) to your Astro site. ๐Ÿ”ผ

@igor.dvlpr/magic-queryselector

๐Ÿช„ A TypeScript-types patch for querySelector/querySelectorAll, make them return types you expect them to! ๐Ÿ”ฎ

@igor.dvlpr/zep

๐Ÿง  Zep is a zero-dependency, efficient debounce module. โฐ

@igor.dvlpr/keppo

๐ŸŽก Parse, manage, compare and output SemVer-compatible version numbers. ๐Ÿ›ก


๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Author

Created by Igor Dimitrijeviฤ‡ (@igorskyflyer).