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

@ryn-bsd/is-file

v1.2.1

Published

a js package help to check files format

Downloads

21

Readme

JS Library helps to check file formats, in node and web.

API

  • isApplication
  • isImage
  • isVideo
  • isAudio
  • isModel
  • isText
  • isFont

Those functions need one parameter, exactly file. Files can be passed as path string, Buffer, Readable

If you want a custom one, call

  • isCustom Accept file and the mime or extension

How to import

import isFile from "@ryn-bsd/is-file"; // base on your environment it will import node or web functionalities

Examples

// Single //

import isFile from "@ryn-bsd/is-file";

isFile.isApplication("text.xml");
// => true, otherwise false

isFile.isImage("image.png");
// => true, otherwise false

isFile.isVideo("video.mp4");
// => true, otherwise false

isFile.isAudio("audio.mp3");
// => true, otherwise false

isFile.isFont("font.ttf");
// => true, otherwise false

isFile.isModel("model.glb");
// => true, otherwise false

isFile.isCustom("custom.png", "image/png");
// => true, otherwise false

isFile.isCustom("custom.png", "png");
// => true, otherwise false
// Multiple //

import isFile from "@ryn-bsd/is-file";

isFile.isApplication(["application.xml", "application.pdf"]);
// => [{ valid: true, value: "application.xml" }, { valid: true, value: "application.pdf" }]

isFile.isCustom(["custom.png", "custom.xml", "custom.glb"], "image/png");
// => [{ valid: true, value: "custom.png" }, { valid: false, value: "custom.xml" }, { valid: false, value: "custom.glb" }]

Core

// Core //

import { Node } from "@ryn-bsd/is-file"; // Node core
import { Web } from "@ryn-bsd/is-file"; // Web core
import { typeFn } from "@ryn-bsd/is-file";

// This is the core function for the library you can import it like this,
// and use it, If it detect the file format if return an object
// otherwise undefined

typeFn("image.png");
// => { mime: "image/png", ext: png }, otherwise undefined

How it work?

The library check file format by it signature (not extension), to ensure the exact file format. In case you pass multiple files in array the library use concurrency model to optimize the performance.