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

@faissaloux/gemfile

v1.1.0

Published

gemfile parser

Downloads

14

Readme

Gemfile

Tests codecov npm version GitHub license

Installation

Install @faissaloux/gemfile using the package manager you want:

    npm install @faissaloux/gemfile
    yarn add @faissaloux/gemfile

Usage


@faissaloux/gemfile can parse both Gemfile and Gemfile.lock.

Gemfile

You can either parse a whole Gemfile file by passing its name to file().

# Gemfile

gem "json", ">= 2.0.0", "!=2.7.0", platforms: [:windows, :jruby]
gem "error_highlight", ">= 0.4.0", platforms: :ruby
gem "sdoc", git: "https://github.com/rails/sdoc.git", branch: "main"
gem "websocket-client-simple", github: "matthewd/websocket-client-simple", branch: "close-race", require: false
// index.js

import { Parser } from '@faissaloux/gemfile';

const parser = new Parser();

let parsed = parser.file('Gemfile').parse();

Or parse Gemfile text by passing it to text().

import { Parser } from '@faissaloux/gemfile';

const parser = new Parser();

let parsed = parser.text(`
    gem "json", ">= 2.0.0", "!=2.7.0", platforms: [:windows, :jruby]
    gem "error_highlight", ">= 0.4.0", platforms: :ruby
    gem "sdoc", git: "https://github.com/rails/sdoc.git", branch: "main"
    gem "websocket-client-simple", github: "matthewd/websocket-client-simple", branch: "close-race", require: false
`).parse();

Result

// console.log(parsed);

{
    "dependencies": [
        {
            "name": "json",
            "version": ">= 2.0.0, != 2.7.0",
            "platforms": [
                "windows",
                "jruby"
            ]
        },
        {
            "name": "error_highlight",
            "version": ">= 0.4.0",
            "platforms": [
                "ruby"
            ]
        },
        {
            "name": "sdoc",
            "git": "https://github.com/rails/sdoc.git",
            "branch": "main"
        },
        {
            "name": "websocket-client-simple",
            "require": "false",
            "github": "matthewd/websocket-client-simple",
            "branch": "close-race"
        }
    ]
}

Gemfile.lock

You can use file() to parse the Gemfile.lock file.

PATH
  remote: .
  specs:
    actioncable (7.2.0.alpha)
      actionpack (= 7.2.0.alpha)
      activesupport (= 7.2.0.alpha)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
      zeitwerk (~> 2.6)

GEM
  remote: https://rubygems.org/
  specs:
    addressable (2.8.6)
      public_suffix (>= 2.0.2, < 6.0)
    amq-protocol (2.3.2)
    ast (2.4.2)
    aws-eventstream (1.3.0)
    aws-partitions (1.876.0)
    aws-sdk-core (3.190.1)
      aws-eventstream (~> 1, >= 1.3.0)
      aws-partitions (~> 1, >= 1.651.0)
      aws-sigv4 (~> 1.8)
      jmespath (~> 1, >= 1.6.1)

PLATFORMS
  ruby
  x86_64-darwin
  x86_64-linux

DEPENDENCIES
  activerecord-jdbcmysql-adapter (>= 1.3.0)
  aws-sdk-s3
import { LockParser } from '@faissaloux/gemfile';

const lockParser = new LockParser();

let parsed = lockParser.file('Gemfile.lock').parse();

Or you can use text() to parse Gemfile.lock content.

import { LockParser } from '@faissaloux/gemfile';

const lockParser = new LockParser();

let parsed = lockParser.text(`PATH
    remote: .
    specs:
    actioncable (7.2.0.alpha)
        actionpack (= 7.2.0.alpha)
        activesupport (= 7.2.0.alpha)
        nio4r (~> 2.0)
        websocket-driver (>= 0.6.1)
        zeitwerk (~> 2.6)

GEM
    remote: https://rubygems.org/
    specs:
    addressable (2.8.6)
        public_suffix (>= 2.0.2, < 6.0)
    amq-protocol (2.3.2)
    ast (2.4.2)
    aws-eventstream (1.3.0)
    aws-partitions (1.876.0)
    aws-sdk-core (3.190.1)
        aws-eventstream (~> 1, >= 1.3.0)
        aws-partitions (~> 1, >= 1.651.0)
        aws-sigv4 (~> 1.8)
        jmespath (~> 1, >= 1.6.1)

PLATFORMS
  ruby
  x86_64-darwin
  x86_64-linux

DEPENDENCIES
  activerecord-jdbcmysql-adapter (>= 1.3.0)
  aws-sdk-s3
`).parse();

Result

// console.log(parsed);

{
    "PATH": {
        "remote": ".",
        "specs": {
            "actioncable (7.2.0.alpha)": [
                "actionpack (= 7.2.0.alpha)",
                "activesupport (= 7.2.0.alpha)",
                "nio4r (~> 2.0)",
                "websocket-driver (>= 0.6.1)",
                "zeitwerk (~> 2.6)"
            ]
        }
    },
    "GEM": {
        "remote": "https://rubygems.org/",
        "specs": {
            "addressable (2.8.6)": [
                "public_suffix (>= 2.0.2, < 6.0)"
            ],
            "amq-protocol (2.3.2)": [],
            "ast (2.4.2)": [],
            "aws-eventstream (1.3.0)": [],
            "aws-partitions (1.876.0)": [],
            "aws-sdk-core (3.190.1)": [
                "aws-eventstream (~> 1, >= 1.3.0)",
                "aws-partitions (~> 1, >= 1.651.0)",
                "aws-sigv4 (~> 1.8)",
                "jmespath (~> 1, >= 1.6.1)"
            ]
        }
    },
    "PLATFORMS": [
        "ruby",
        "x86_64-darwin",
        "x86_64-linux"
    ],
    "DEPENDENCIES": [
        "activerecord-jdbcmysql-adapter (>= 1.3.0)",
        "aws-sdk-s3"
    ]
}

Parser filter

You can choose which elements to return using only().

Parser.only("name", "platforms");
import { Parser } from '@faissaloux/gemfile';

Parser.only("name", "platforms");

const parser = new Parser();
let parsed = parser.text(`
    gem "json", ">= 2.0.0", "!=2.7.0", platforms: [:windows, :jruby]
    gem "error_highlight", ">= 0.4.0", platforms: :ruby
    gem "sdoc", git: "https://github.com/rails/sdoc.git", branch: "main"
    gem "websocket-client-simple", github: "matthewd/websocket-client-simple", branch: "close-race", require: false
`).parse();
// console.log(parsed);

{
    "dependencies": [
        {
            "name": "json",
            "platforms": [
                "windows",
                "jruby"
            ]
        },
        {
            "name": "error_highlight",
            "platforms": [
                "ruby"
            ]
        },
        {
            "name": "sdoc"
        },
        {
            "name": "websocket-client-simple"
        }
    ]
}

LockParser filter

You can choose which sections to return using only().

LockParser.only("PLATFORMS", "DEPENDENCIES");
import { LockParser } from '@faissaloux/gemfile';

LockParser.only("PLATFORMS", "DEPENDENCIES");

const lockParser = new LockParser();
let parsed = lockParser.text(`
PATH
    remote: .
    specs:
    actioncable (7.2.0.alpha)
        actionpack (= 7.2.0.alpha)
        activesupport (= 7.2.0.alpha)
        nio4r (~> 2.0)
        websocket-driver (>= 0.6.1)
        zeitwerk (~> 2.6)

PLATFORMS
    ruby
    x86_64-darwin
    x86_64-linux

DEPENDENCIES
    activerecord-jdbcmysql-adapter (>= 1.3.0)
    aws-sdk-s3

BUNDLED WITH
    2.5.4
`).parse();
// console.log(parsed);

{
    "PLATFORMS": [
        "ruby",
        "x86_64-darwin",
        "x86_64-linux"
    ],
    "DEPENDENCIES": [
        "activerecord-jdbcmysql-adapter (>= 1.3.0)",
        "aws-sdk-s3"
    ]
}