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

lnk

v1.1.0

Published

Create links between files cross-platform

Downloads

30,188

Readme

lnk Build Status Build status Coverage Status XO code style

Create links between files cross-platform

Why

  • Promise interface
  • Create hard links, directory junctions and symbolic links depending on the platform

Install

$ npm install lnk --save

Usage

$ tree
.
└── assets
    ├── favicon.ico
    └── style
        ├── app.css
        └── vendor.css

2 directories, 3 files
const lnk = require('lnk');

lnk(['assets/favicon.ico', 'assets/style'], 'dist')
	.then(() => console.log('done'));
$ tree
.
├── assets
│   ├── favicon.ico
│   └── style
│       ├── app.css
│       └── vendor.css
└── dist
    ├── favicon.ico              // hard link to assets/favicon.ico
    └── style -> ../assets/style // symlink; directory junction on windows

4 directories, 4 files

Glob support

lnk don't support globbing by itself, lnk supports arrays of targets and Promises which resolve to these though:

const lnk = require('lnk');
const globby = require('globby');  // npm install globby

lnk(globby('assets/*'), 'dist')
	.then(() => console.log('done'));

API

lnk provides a cross-platform convenience wrapper for the fs.link and fs.symlink functions.

lnk(targets, directory, [opts])

Returns a Promise.

lnk.sync (targets, directory, [opts])

Synchronous version of lnk.

targets

Type: string|string[]

Targets of the links. lnk() additionally supports Promise<string|string[]>.

directory

Type: string

Destination directory.

opts

Type: object

cwd

Type: string Default: process.cwd()

The current working directory for targets and directory.

force

Type: boolean Default: false

Overwrite existing files.

type

Type: string Values: 'default', 'hard', 'symbolic', 'junction' or 'directory' Default: 'default'

By 'default', lnk tries to create hard links, if this fails for a target because it is a directory lnk tries to create a directory junction (symbolic link on modern OSs) for this target.

parents

Type: boolean Default: false

Use full source file name under directory.

// w/o parents:
lnk('assets/style/foo.css', 'dist/assets/style', ...);

// w/ parents:
lnk('assets/style/foo.css', 'dist', {parents: true}, ...);
rename

Type: string|object|function(object):(string|object)

Filepath or function mapping a path object to a filename or path object; used to modify the path of the link before creating.

Basic Example
$ tree
.
└── assets
    ├── favicon.ICO
    └── style
        ├── app.css
        └── vendor.css
const path = require('path');

Promise.all([
	lnk('assets/style', 'dist', {rename: 'css'}),
	lnk('assets/favicon.ICO', 'dist', {rename: pathOfLink => pathOfLink.base.toLowerCase()})
]).then(() => console.log('done'));
$ tree
.
├── assets
│   ├── favicon.ICO
│   └── style
│       ├── app.css
│       └── vendor.css
└── dist
    ├── css -> ../assets/style // symlink; directory junction on windows
    └── favicon.ico            // hard link to assets/favicon.ICO
Sophisticated Example
$ tree
.
└── assets
    ├── favicon.ico
    └── style
        ├── app.css
        └── vendor.css
const rename = pathOfLink => Object.assign(pathOfLink, {
	dir: path.join(pathOfLink.dir, '42'),
	base: `prefix-${pathOfLink.name}` + pathOfLink.ext.toLowerCase()
});

lnk(['assets/favicon.ico', 'assets/style'], 'dist', {rename})
	.then(() => console.log('done'));
$ tree
.
├── assets
│   ├── favicon.ico
│   └── style
│       ├── app.css
│       └── vendor.css
└── dist
    └── 42
        ├── prefix-favicon.ico                 // hard link to assets/favicon.ico
        └── prefix-style -> ../../assets/style // symlink; directory junction on windows
log

Type: function Default: (level, prefix, message) => {}

A logger function, you may want to use console.log or npmlog.log, see npmlog documentation for details.

Related

  • lnk-cli – CLI version of this project
  • globby – if you need glob support for multiple patterns
  • cpy – if you need to copy multiple files
  • del – if you need to delete files and folders

License

MIT © Michael Mayer