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@dimcheify/dimui@compositive/commons-processing@compositive/artifact-npm@cybermega/flutter-resource-manager-rs@currents/cc-est@daiki48/keisan@deploysentinel/cypress-parallel@bung87/ostoolcustom-react-app1custom-react-app2jolt-frameworkjulien-easy-modaljetbolt-reactstyle-guide-mainstart-typescriptsource-map-diffuimo@anonybit-modules/videoreconstruction@atlaspack/lsp@airthium/air-jsdoc-template@biothings-explorer/api-response-transform@biothings-explorer/json-transformer@chi_eee/another-test-package@abtnode/cli128981semzub@codemayonnaise/react-refresh-webpack-plugin@belsonn/cczt-bundlerzszilvai-cy-cloudzubtesttodayvirtual-tour-guidevimo-sketchesvimodev@hippy/hippy-react-refresh-webpack-plugin@govuk-one-login/authentication-spinner@infinitebrahmanuniverse/nolb-common-@kui-shell/plugin-s3@krivega/cc@luciadias/storybook-notimation@lego-js/tests@leiyulf/gantt-task-react@itayn-fireberry-org/itayn-test@lihancong/react-refresh-webpack-plugin@lui-dias/swc-napi@manuth/generator-ts-project@my-wufan/hello-napi@netlify/zip-it-and-ship-it@netlify/edge-bundler@enirisdev/angular-google-charts@modern-js/react-refresh-webpack-plugin@mayuriachewad/pickupbiz-npm-package@mometa/react-refresh-webpack-plugin@johnhamlin/redux-persist@knooks/use-title@jsdoc/template-legacy@jsdoc/tag@img-arena/img-ui-mui-theme@img-arena/ui-core@jg-tpll/malti_search@juanaraneta/dept-central-lib-client@morlay/ava@qrcode-rs/qrcode@rx-now/analysis-core@rx-now/eslint-plugin@rx-now/lint-rules@rehanasif/react-auth-hocs@pixi/webdoc-template@podlubnaja/ui-kit@nota-lang/esbuild-utils@npmtuanmap2024/nihil-officia-perferendis@parcel/lsp@skeetboothppq/component-library@soyjak/utils@shivarajapple/first-library@srob/filesmy-library-buttonmy-testing-npm-pluginsmynancemicroend-componentmyrepofilemypluginlolmy-framework-clip147-table
3.0.0

6 years ago

2.0.0

6 years ago

1.0.0

9 years ago