initial commit of actions

This commit is contained in:
2026-01-31 18:56:04 +01:00
commit 949ece5785
44660 changed files with 12034344 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
ISC License (ISC)
Copyright (c) 2016, Mark Wubben
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

View File

@@ -0,0 +1,51 @@
# 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
```console
npm install common-path-prefix
```
## Usage
The module has one default export, the `commonPathPrefix` function:
```js
const commonPathPrefix = require('common-path-prefix')
```
Call `commonPathPrefix()` with an array of paths (strings) and an optional separator character:
```js
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:
```js
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:
```js
commonPathPrefix(['foo$bar', 'foo$baz'], '$') // returns 'foo$''
```
An empty string is returned if no common prefix exists:
```js
commonPathPrefix(['foo/bar', 'baz/qux']) // returns ''
commonPathPrefix(['foo/bar']) // returns ''
```
Note that the following *does* have a common prefix:
```js
commonPathPrefix(['/foo/bar', '/baz/qux']) // returns '/'
```

View File

@@ -0,0 +1,3 @@
declare function commonPathPrefix(paths: string[], sep?: string): string;
export = commonPathPrefix;

View File

@@ -0,0 +1,33 @@
'use strict'
const { sep: DEFAULT_SEPARATOR } = require('path')
const determineSeparator = paths => {
for (const path of paths) {
const match = /(\/|\\)/.exec(path)
if (match !== null) return match[0]
}
return DEFAULT_SEPARATOR
}
module.exports = function commonPathPrefix (paths, sep = determineSeparator(paths)) {
const [first = '', ...remaining] = paths
if (first === '' || remaining.length === 0) return ''
const parts = first.split(sep)
let endOfPrefix = parts.length
for (const path of remaining) {
const compare = path.split(sep)
for (let i = 0; i < endOfPrefix; i++) {
if (compare[i] !== parts[i]) {
endOfPrefix = i
}
}
if (endOfPrefix === 0) return ''
}
const prefix = parts.slice(0, endOfPrefix).join(sep)
return prefix.endsWith(sep) ? prefix : prefix + sep
}

View File

@@ -0,0 +1,41 @@
{
"name": "common-path-prefix",
"version": "3.0.0",
"description": "Computes the longest prefix string that is common to each path, excluding the base component",
"main": "index.js",
"files": [
"index.d.ts",
"index.js"
],
"scripts": {
"test": "standard && nyc ava"
},
"repository": {
"type": "git",
"url": "git+https://github.com/novemberborn/common-path-prefix.git"
},
"author": "Mark Wubben (https://novemberborn.net/)",
"license": "ISC",
"bugs": {
"url": "https://github.com/novemberborn/common-path-prefix/issues"
},
"homepage": "https://github.com/novemberborn/common-path-prefix#readme",
"keywords": [
"common",
"path",
"directory",
"dir",
"file",
"root",
"typescript",
"common prefix",
"common path",
"common path start",
"common root"
],
"devDependencies": {
"ava": "^2.3.0",
"nyc": "^14.1.1",
"standard": "^14.0.2"
}
}