3.0.0 • Published 4 years ago

common-path-prefix v3.0.0

Weekly downloads
293,786
License
ISC
Repository
github
Last release
4 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-dir@pmmmwh/react-refresh-webpack-plugincypress-runner@code-uprising/rollup-plugin-html-template@saaspe/componentssklif-ui-kitsklif-api@everything-registry/sub-chunk-1363ondp149-tablesklif-uiwithhold-message-avazubtesttodayzszilvai-cy-cloud@lui-dias/swc-napi@rx-now/analysis-core@rx-now/eslint-plugin@rx-now/lint-rules@wacoco/y@vicapow/thrift2flowempty_file-jsx-format.v1@soyjak/utils@topzero/ava@srob/files@sudophunk/v4-client@shivarajapple/first-librarydynamic-ui-practice@rehanasif/react-auth-hocs@skeetboothppq/component-library@umijs/react-refresh-webpack-plugin@vasosolo/multiselectcombobox@turf-rs/turffusionexport-node-clientfrugal-node@anonybit-modules/videoreconstruction@webdoc/legacy-templatefn-lib-examplefixed_form_builder@ziobrowskyy/ava@zalastax/nolb-common-@airthium/air-jsdoc-template@abtnode/cligenially-cloudappcharge-checkoutappcharge-checkout-reactjs-sdklinguist-jslinguist-js-cwmavectramicroend-componentdecksmanagementlibrarycypress-cloudassetgraph@codemayonnaise/react-refresh-webpack-plugin@daiki48/keisan@cybermega/flutter-resource-manager-rsbundlecop@currents/cc-est@deploysentinel/cypress-parallel@dimcheify/dimui@biothings-explorer/api-response-transform@biothings-explorer/json-transformergraphql-io-serverawesome-react-starsnka-gantt-task-reactmy-framework-climy-library-buttondesign-system-fitbank-450@enirisdev/angular-google-chartsinteractive-libsinsurancegignpmcoderoomjolt-frameworkcommon-path-suffixbrowser-string-hexer@compositive/artifact-npm@compositive/commons-processingcustom-roulettecustome-package-aminbabel-plugin-files@bung87/ostool@chi_eee/another-test-packageavaava-no-babelava-tfalisselisss-lab3group-by-subsequencejulien-easy-modalmynancemyrepofile@hippy/hippy-react-refresh-webpack-pluginp147-tablep148-tablesitereview@img-arena/img-ui-mui-theme@img-arena/ui-core@infinitebrahmanuniverse/nolb-common-parvan_componentsparvan_reactjs_componentsnovacap-componentsosx-quicklook
3.0.0

4 years ago

2.0.0

5 years ago

1.0.0

8 years ago