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-rs@bung87/ostoolcustom-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@itayn-fireberry-org/itayn-test128981semzub22501a0548@atlaspack/lsp@hahahoarder/strawberry-ui@abtnode/cli@airthium/air-jsdoc-template@codemayonnaise/react-refresh-webpack-plugin@compositive/artifact-npm@compositive/commons-processing@amarislabs/bun-plugin-dtsstyle-guide-mainstart-typescriptsource-map-diffuimo@biothings-explorer/api-response-transform@biothings-explorer/json-transformer@chi_eee/another-test-package@belsonn/cczt-bundlerzszilvai-cy-cloudzubtesttodayvirtual-tour-guidevimo-sketchesvimodev@infinitebrahmanuniverse/nolb-common-@kui-shell/plugin-s3@krivega/cc@lego-js/tests@leiyulf/gantt-task-react@lihancong/react-refresh-webpack-plugin@my-wufan/hello-napi@netlify/zip-it-and-ship-it@netlify/edge-bundler@modern-js/react-refresh-webpack-plugin@mometa/react-refresh-webpack-plugin@knooks/use-title@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@parcel/lspmy-library-buttonmy-testing-npm-pluginsmynancemicroend-component
3.0.0

6 years ago

2.0.0

6 years ago

1.0.0

10 years ago