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

user-attachments

v1.1.2

Published

upload file to github

Downloads

242

Readme

user-attachments

upload file to github

install

pnpm add user-attachments

usage

import fs from 'node:fs/promises';
import process from 'node:process';
import { uploadPoliciesAssets } from 'user-attachments';

const asset = await uploadPoliciesAssets({
  cookie: await fs.readFile(process.cwd() + '/test/cookie.txt', 'utf-8'),
  file: new File(['233'], 'file.txt'),
});

console.log(asset);
/*
{
  id: 15856568,
  name: 'file.txt',
  size: 3,
  content_type: 'text/plain',
  href: 'https://github.com/user-attachments/files/15856568/file.txt',
  original_name: 'file.txt'
}
*/

/*
// if you uplod image
{
  id: 340077278,
  name: 'test.png',
  size: 119,
  content_type: 'image/png',
  href: 'https://github.com/user-attachments/files/assets/38517192/a7d6a234-6019-44e0-a8a8-e4bc145c852c',
  original_name: 'test.png'
}
*/

options

export type UolpadOptions = {
  file: File;

  /**
   * the cookie string of the github page, you can get it from the browser developer tools
   *
   * if you not set it, you must set fetch parameter
   */
  cookie?: string;

  /**
   * the gihtub page url where the file will be uploaded, it must be a page that contains the file-attachment element
   * @default
   * 'https://github.com/lisonge/user-attachments/issues/1'
   */
  url?: string;

  /**
   * get the authenticity token and repository id from the page
   */
  getAuthenticity?: () => Promise<Authenticity> | Authenticity;

  /**
   * if you want to use a custom fetch function to skip cors limitation
   *
   * or you can use it to set the cookie
   *
   * @default globalThis.fetch
   */
  fetch?: SubFetch;
};