3.0.0 • Published 6 years ago

common-path-prefix v3.0.0

Weekly downloads
293,786
License
ISC
Repository
github
Last release
6 years ago

common-path-prefix

Computes the longest prefix string that is common to each path, excluding the base component. Tested with Node.js 8 and above.

Installation

npm install common-path-prefix

Usage

The module has one default export, the commonPathPrefix function:

const commonPathPrefix = require('common-path-prefix')

Call commonPathPrefix() with an array of paths (strings) and an optional separator character:

const paths = ['templates/main.handlebars', 'templates/_partial.handlebars']

commonPathPrefix(paths, '/') // returns 'templates/'

If the separator is not provided the first / or \ found in any of the paths is used. Otherwise the platform-default value is used:

commonPathPrefix(['templates/main.handlebars', 'templates/_partial.handlebars']) // returns 'templates/'
commonPathPrefix(['templates\\main.handlebars', 'templates\\_partial.handlebars']) // returns 'templates\\'

You can provide any separator, for example:

commonPathPrefix(['foo$bar', 'foo$baz'], '$') // returns 'foo$''

An empty string is returned if no common prefix exists:

commonPathPrefix(['foo/bar', 'baz/qux']) // returns ''
commonPathPrefix(['foo/bar']) // returns ''

Note that the following does have a common prefix:

commonPathPrefix(['/foo/bar', '/baz/qux']) // returns '/'
find-cache-dircypress-runner@code-uprising/rollup-plugin-html-template@saaspe/componentssklif-ui-kitsklif-api@everything-registry/sub-chunk-1363ondp149-tablesklif-uicomposize@wacoco/ywhitegarddenwithhold-message-avateapackage-tatespoorman297textstatthrift2flow@cybermega/flutter-resource-manager-rscustom-react-app1custom-react-app2jolt-frameworkjulien-easy-modaljetbolt-reacthttp-nfinsurancegignpminterworky-assistantinteractive-libsinteractive-decks-libhusam3linguist-jslinguist-js-cwmavectra@webdoc/legacy-template@umijs/react-refresh-webpack-plugin@turf-rs/turf@topzero/ava@vicapow/thrift2flow@vasosolo/multiselectcombobox@ykominami/xcomp@zalastax/nolb-common-alisselisss-lab3@ziobrowskyy/avaajs-projectbabel-plugin-filesawesome-react-starsassetgraphanimejs-overrideappcharge-checkout@govuk-one-login/authentication-spinner@hahahoarder/strawberry-uistyle-guide-mainstart-typescriptsource-map-diffuimo@chi_eee/another-test-packagezt-bundlerzszilvai-cy-cloudzubtesttodayvirtual-tour-guidevimo-sketchesvimodev@infinitebrahmanuniverse/nolb-common-@kui-shell/plugin-s3@lego-js/tests@leiyulf/gantt-task-react@lihancong/react-refresh-webpack-pluginmy-library-buttonmy-testing-npm-pluginsmynancemicroend-componentmyrepofilemypluginlolmy-framework-clip147-tablep148-tableosx-quicklookotus-functional-developmentnovacap-componentsparvan_componentsparvan_reactjs_componentssearch-utilsreact-ang-notifications-honey-comb-setupreact-component-fresh-webpack-pluginreact-lightbox-pack-18supportscrollflowsemantic-release-gitmoji-actionreact-form-component-libraryreact-gantt-chart7nka-gantt-task-reactpickupbiz-npm-packagepixi-webdoc-templateplugin-corejspolyglot-component-libraryredux-actions-immutablequran-page-packagereactofy-css-libraryproparallaxresponsis-gantt-task-reactreact-solid-gradient-pickersitereview
3.0.0

6 years ago

2.0.0

6 years ago

1.0.0

10 years ago