Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .bitmap
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@
"mainFile": "index.ts",
"rootDir": "util/lex-comparator"
},
"nerf-dart": {
"name": "nerf-dart",
"scope": "",
"version": "",
"defaultScope": "pnpm.config",
"mainFile": "index.ts",
"rootDir": "config/nerf-dart",
"config": {
"pnpm.env/envs/pnpm-env": {},
"teambit.envs/envs": {
"env": "pnpm.env/envs/pnpm-env"
}
}
},
"policy": {
"name": "policy",
"scope": "pnpm.builder",
Expand Down
15 changes: 15 additions & 0 deletions config/nerf-dart/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The ISC License

Copyright (c) npm, Inc.

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.
1 change: 1 addition & 0 deletions config/nerf-dart/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { nerfDart } from './nerf-dart'
13 changes: 13 additions & 0 deletions config/nerf-dart/nerf-dart.docs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
labels: ['NerfDart', 'module']
description: 'Maps a URL to an identifier.'
---

```ts
import { nerfDart } from 'nerf-dart'

nerfDart('http://registry.npmjs.org')
//> //registry.npmjs.org/
```

Originally from npm. Taken from <https://github.com/npm/cli/blob/latest/workspaces/config/lib/nerf-dart.js> and made available as a standalone package for easier reuse.
41 changes: 41 additions & 0 deletions config/nerf-dart/nerf-dart.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { nerfDart } from './nerf-dart'

test.each([
['//registry.npmjs.org/', [
'https://registry.npmjs.org',
'https://registry.npmjs.org/package-name',
'https://registry.npmjs.org/package-name?write=true',
'https://registry.npmjs.org/@scope%2fpackage-name',
'https://registry.npmjs.org/@scope%2fpackage-name?write=true',
'https://username:password@registry.npmjs.org/package-name?write=true',
'https://registry.npmjs.org/#hash',
'https://registry.npmjs.org/?write=true#hash',
'https://registry.npmjs.org/package-name?write=true#hash',
'https://registry.npmjs.org/package-name#hash',
'https://registry.npmjs.org/@scope%2fpackage-name?write=true#hash',
'https://registry.npmjs.org/@scope%2fpackage-name#hash',
]],
['//my-couch:5984/registry/_design/app/rewrite/', [
'https://my-couch:5984/registry/_design/app/rewrite/',
'https://my-couch:5984/registry/_design/app/rewrite/package-name',
'https://my-couch:5984/registry/_design/app/rewrite/package-name?write=true',
'https://my-couch:5984/registry/_design/app/rewrite/@scope%2fpackage-name',
'https://my-couch:5984/registry/_design/app/rewrite/@scope%2fpackage-name?write=true',
'https://username:password@my-couch:5984/registry/_design/app/rewrite/package-name?write=true',
'https://my-couch:5984/registry/_design/app/rewrite/#hash',
'https://my-couch:5984/registry/_design/app/rewrite/?write=true#hash',
'https://my-couch:5984/registry/_design/app/rewrite/package-name?write=true#hash',
'https://my-couch:5984/registry/_design/app/rewrite/package-name#hash',
'https://my-couch:5984/registry/_design/app/rewrite/@scope%2fpackage-name?write=true#hash',
'https://my-couch:5984/registry/_design/app/rewrite/@scope%2fpackage-name#hash',
]],
])('nerfDart', (dart, tests) => {
expect.assertions(tests.length)
for (const url of tests) {
expect(nerfDart(url)).toBe(dart)
}
})

test('nerfDart to throw', () => {
expect(() => nerfDart('not a valid url')).toThrow()
})
18 changes: 18 additions & 0 deletions config/nerf-dart/nerf-dart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { URL } from 'url'

/**
* Maps a URL to an identifier.
*
* Name courtesy schiffertronix media LLC, a New Jersey corporation
*
* @param {String} url The URL to be nerfed.
*
* @returns {String} A nerfed URL.
*/
export function nerfDart (url: string): string {
const parsed = new URL(url)
const from = `${parsed.protocol}//${parsed.host}${parsed.pathname}`
const rel = new URL('.', from)
const res = `//${rel.host}${rel.pathname}`
return res
}
3 changes: 0 additions & 3 deletions env/envs/pnpm-env/types/nerf.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
declare module 'nerf-dart' {
export default function (uri: string): string;
}
2 changes: 1 addition & 1 deletion network/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import nerfDart from 'nerf-dart';
import { nerfDart } from '@pnpm/config.nerf-dart';

function getMaxParts(uris: string[]) {
return uris.reduce((max, uri) => {
Expand Down
Loading
Loading