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

devlink-core

v1.0.6

Published

Package that can create symbolic links and unlinks more robust way with possibility revert it.

Downloads

24

Readme

Servant devlink-core

Pipeline Npm Downloads License Node Collaborators

What is it?

Devlink is a simple tool, that can create symbolic link in your system from source to destination file. Usage is really simple and there are more ways how to use this api. It's implemented as functional, promise, throwable and with callbacks. Devlink keeps original file, so you can always revert link operation by unlink operation, that's return previous file.

functional API

function link(on: string, to: string): Either<LinkError, LinkResult>

This is a functional alternative of link method. This method take 2 parameters and return Either monad, that contains LinkError if method fail or LinkResults if everything is done correctly. This method create link from on file to to file.

Parameters:

  1. on - path to file when we need to create link, file must exist
  2. to - path to file where link will be pointing, file must exist

Returns:

  • Either<LinkError, LinkResult>

Example:

import { functional } from "devlink-core";

const { link } = functional;
const result = link("/data/sources/source.txt", "/data/links/link.txt");

function unlink(on: string): Either<UnlinkError, UnlinkResult>

This is a functional alternative of unlink method. This method take 1 parameter and return Either monad, that contains UnlinkError if method fail or UnlinkResult if everything is done correctly. This method remove link created by link method on on file.

Parameters:

  1. on - path to file where link is created, file must exist

Returns:

  • Either<UnlinkError, UnlinkResult>

Example:

import { functional } from "devlink-core";

const { unlink } = functional;
const result = unlink("/data/sources/source.txt");

function linked(on: string): E.Either<never, LinkedResult>

This is a functional alternative of linked method. This method take 1 parameter and return Either monad, that contains LinkedResult if everything is done correctly. This method never fail. This method is used to check if on file exists link, that is created by link function.

Parameters:

  1. on - path to file where we want to check if link is created

Returns:

  • Either<never, LinkedResult>

Example:

import { functional } from "devlink-core";

const { linked } = functional;
const result = linked("/data/sources/source.txt");

promise API

function link(on: string, to: string): Promise<LinkResult>

This is a promise alternative of link method. This method take 2 parameters and return promise, that return LinkResults if everything is done correctly and catch LinkError if fails. This method create link from on file to to file.

Parameters:

  1. on - path to file when we need to create link, file must exist
  2. to - path to file where link will be pointing, file must exist

Returns:

  • Promise<LinkResult>

Catch:

  • LinkError

Example:

import { promise } from "devlink-core";

const { link } = promise;
link("/data/sources/source.txt", "/data/links/link.txt")
	.then((result) => {})
	.catch((err) => {});

function unlink(on: string): Promise<UnlinkResult>

This is a promise alternative of unlink method. This method take 1 parameter and return promise, that return UnlinkResult if everything is done correctly and catch LinkError if fails. This method remove link created by link method on on file.

Parameters:

  1. on - path to file where link is created, file must exist

Returns:

  • Promise<UnlinkResult>

Catch:

  • LinkError

Example:

import { promise } from "devlink-core";

const { unlink } = promise;
unlink("/data/sources/source.txt")
	.then((result) => {})
	.catch((err) => {});

function linked(on: string): Promise<LinkedResult | null>

This is a promise alternative of linked method. This method take 1 parameter and return promise, that contains LinkedResult if everything is done correctly. This method never fail. This method is used to check if on file exists link, that is created by link function.

Parameters:

  1. on - path to file where we want to check if link is created

Returns:

  • Promise<LinkedResult | null>

Example:

import { promise } from "devlink-core";

const { linked } = promise;
linked("/data/sources/source.txt").then((result) => {});

throwable API

function link(on: string, to: string): LinkResult

This is a throwable alternative of link method. This method take 2 parameters and return result LinkResults if everything is done correctly and throw LinkThrow if fails. This method create link from on file to to file.

Parameters:

  1. on - path to file when we need to create link, file must exist
  2. to - path to file where link will be pointing, file must exist

Returns:

  • LinkResult

Throw:

  • LinkThrow

Example:

import { throwable } from "devlink-core";

const { link } = throwable;
try {
	const results = link("/data/sources/source.txt", "/data/links/link.txt");
} catch (err) {
	// handle error
}

function unlink(on: string): Promise<UnlinkResult>

This is a throwable alternative of unlink method. This method take 1 parameter and return UnlinkResult if everything is done correctly and throw LinkThrow if fails. This method remove link created by link method on on file.

Parameters:

  1. on - path to file where link is created, file must exist

Returns:

  • UnlinkResult

Throw:

  • LinkThrow

Example:

import { throwable } from "devlink-core";

const { unlink } = throwable;
try {
	const results = unlink("/data/sources/source.txt");
} catch (err) {
	// handle error
}

function linked(on: string): Promise<LinkedResult | null>

This is a throwable alternative of linked method. This method take 1 parameter and return LinkedResult if everything is done correctly or null if there is some error. This method never fail. This method is used to check if on file exists link, that is created by link function.

Parameters:

  1. on - path to file where we want to check if link is created

Returns:

  • LinkedResult | null

Example:

import { throwable } from "devlink-core";

const { linked } = throwable;
const result = linked("/data/sources/source.txt");

callback API

function link(on: string, to: string, onDone: (err: LinkThrow | null, res: LinkResult | null) => void): void

This is a callback alternative of link method. This method take 3 parameters and return void. Last parameter is callback function with error LinkThrow and result LinkResults. If something failed result parameter is null, is everything is ok, err parameter is null. This method create link from on file to to file.

Parameters:

  1. on - path to file when we need to create link, file must exist
  2. to - path to file where link will be pointing, file must exist
  3. onDone - callback function with err and result

Example:

import { callback } from "devlink-core";

const { link } = callback;
link("/data/sources/source.txt", "/data/links/link.txt", (err, result) => {
	if (result) {
		// handle result
	}
	if (err) {
		// handle error
	}
});

function unlink(on: string, onDone: (err: LinkThrow | null, res: UnlinkResult | null) => void): void

This is a callback alternative of unlink method. This method take 2 parameters and return void. Last parameter is callback function with error LinkThrow and result UnlinkResult. If something failed result parameter is null, is everything is ok, err parameter is null. This method remove link created by link method on on file.

Parameters:

  1. on - path to file where link is created, file must exist
  2. onDone - callback function with err and result

Example:

import { callback } from "devlink-core";

const { unlink } = callback;
unlink("/data/sources/source.txt", (err, result) => {
	if (result) {
		// handle result
	}
	if (err) {
		// handle error
	}
});

function linked(on: string): Promise<LinkedResult | null>

This is a callback alternative of linked method. This method take 2 parameters and return void. Last parameter is callback function with result UnlinkResult or null. If something failed result parameter is null. This method is used to check if on file exists link, that is created by link function.

Parameters:

  1. on - path to file where we want to check if link is created
  2. onDone - callback function with err and result

Example:

import { callback } from "devlink-core";

const { linked } = callback;
linked("/data/sources/source.txt", (result) => {
	if (result) {
		// handle result
	} else {
		// handle error
	}
});

Donate me

| QR | Paypal | | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | |