@io-arc/output-dir-diff

A relative path to another directory from one directory.

Usage#

$ npm i @io-arc/output-dir-diff
index.ts
import OutputDirDiff from '@io-arc/output-dir-diff'
const diff = new OutputDirDiff(['foo', 'bar'], ['foo'])
const res = diff.targetRelativePath()
console.log(res)
// -> '../'

Methods#

Instance parameters#

If the target does not match the base, go back through the entire base array.

paramstypedefaultdescription
basestring[]-Array of directory names to search
targetstring[]-An array of target directories

targetRelativePath()#

Obtain the difference between base and target with a relative path.

example

import OutputDirDiff from '@io-arc/output-dir-diff'
const diff = new OutputDirDiff(['foo', 'bar'], ['foo'])
const res = diff.targetRelativePath()
console.log(res)
// -> '../'
const diff2 = new OutputDirDiff(['foo', 'bar', 'abc'], ['foo'])
const res2 = diff2.targetRelativePath()
console.log(res2)
// -> '../../'
// No match
const diff3 = new OutputDirDiff(['foo', 'bar', 'abc'], ['def'])
const res3 = diff3.targetRelativePath()
console.log(res3)
// -> '../../../def'