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

php-imports

v0.6.1

Published

JavaScript library for formatting PHP imports

Downloads

25

Readme

js-php-imports

Travis CI Build Status npm version

JavaScript library for formatting PHP imports.

Installation

$ npm i --save php-imports

or

$ yarn add php-imports

CLI

This package provides basic cli:

PHP imports formatter

USAGE
  $ php-imports [FILE]

OPTIONS
  -V, --verbose          Print more info
  -c, --config=config    JSON configuration
  -f, --flag=flag        Specify configuration key-value pair
  -h, --help             show CLI help
  -p, --project=project  [default: .] Project directory or .phpimportsrc file
  -v, --version          show CLI version
  --dry                  Don't write any changes to files
  --init                 Create .phpimportsrc file

By default, it uses .phpimportsrc file located at current working directory.

phpimportsrc

It is a json file that contains configuration for this package. You can create this file with $ php-imports --init.

Also, you can specify these flags with -f argument: $ php-imports -f unused.enable=true

It can contain the following options (dot means object nesting):

  • root: Base location of sources. Default is . (current working directory).

  • include: List of files to include (glob patterns) relatively to root (default is src/**/*.php).

  • exclude: List of files to exclude (relatively to root, default is node_modules and vendor).

  • order: Order of import sets and empty lines between them. An array of enums with possible values:

    • emptyLine
    • all.all
    • all.class
    • all.function
    • all.const
    • singleUses.all
    • singleUses.class
    • singleUses.function
    • singleUses.const
    • groupedUses.all
    • groupedUses.class
    • groupedUses.function
    • groupedUses.const
  • sort.order: Order of first-level imports. Possible values: default (alphabetical) or natural (first longest, alphabetical).

  • sort.nestedOrder: Order of second-level imports. Possible values: default (alphabetical) or natural (first longest, alphabetical).

  • print.emptyLinesAfterImports: Count of empty lines between last import and the declaration after it.

  • print.wrap: If false, then nested groups are never wrapped, if true (which is default), then they are always in separate lines.

    You can also set it to number to start wrapping only when line length exceeds that limit.

    Alternatively it can be set to object {"all":false,"limit":120} in order to put as much as possible imports in single line with wrapping still enabled.

  • psr12.enable: Enable PSR-12 imports formatting.

  • psr12.isolateModifiers: Whether to put different modifiers (without modifier, const and function) to different groups.

  • psr12.minNestedGroupNestedUsesCount: Minimum count of nested uses to make a nested group with them.

  • psr12.minNestedGroupUsesCount: Mimimum count of uses to make a nested group with them.

  • psr12.minGroupUsesCount: Mimimum count of uses of same namespace to make a group with them.

  • custom.enable: Enable custom imports formatting.

  • custom.isolateModifiers: Whether to put different modifiers (without modifier, const and function) to different groups.

  • custom.include: A list of namespaces that should always be grouped. Can be used with wildcards (*) and double wildcards (**).

  • custom.exclude: A list of namespaces that should never be grouped.

  • unused.enable: Clean up unused imports.

License

The project is released under the MIT license. Read the license for more information.