Skip to content

Commit

Permalink
Document permuteDomain
Browse files Browse the repository at this point in the history
  • Loading branch information
colincasey committed Mar 17, 2024
1 parent 36b014b commit 6400551
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 34 deletions.
1 change: 1 addition & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ docs/*.md

# subsequent PRs will un-ignore areas that are under review until
# all docs are complete and we can drop this ignore file entirely
!docs/tough-cookie.permutedomain.md
33 changes: 33 additions & 0 deletions api/docs/tough-cookie.permutedomain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [tough-cookie](./tough-cookie.md) &gt; [permuteDomain](./tough-cookie.permutedomain.md)

## permuteDomain() function

Generates the permutation of all possible values that [domainMatch()](./tough-cookie.domainmatch.md) the given `domain` parameter. The array is in shortest-to-longest order. Useful when building custom [Store](./tough-cookie.store.md) implementations.

**Signature:**

```typescript
export declare function permuteDomain(domain: string, allowSpecialUseDomain?: boolean): string[] | null;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| domain | string | the domain to generate permutations for |
| allowSpecialUseDomain | boolean | _(Optional)_ flag to control if [Special Use Domains](https://www.rfc-editor.org/rfc/rfc6761.html) such as <code>localhost</code> should be allowed |

**Returns:**

string\[\] \| null

## Example


```
permuteDomain('foo.bar.example.com')
// ['example.com', 'bar.example.com', 'foo.bar.example.com']
```

2 changes: 1 addition & 1 deletion api/tough-cookie.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export function parseDate(str: string | undefined | null): Date | undefined;
// @public (undocumented)
export function pathMatch(reqPath: string, cookiePath: string): boolean;

// @public (undocumented)
// @public
export function permuteDomain(domain: string, allowSpecialUseDomain?: boolean): string[] | null;

// @public
Expand Down
46 changes: 13 additions & 33 deletions lib/permuteDomain.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
/*!
* Copyright (c) 2015, Salesforce.com, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
import { getPublicSuffix } from './getPublicSuffix'

/**
* Generates the permutation of all possible values that {@link domainMatch} the given `domain` parameter. The
* array is in shortest-to-longest order. Useful when building custom {@link Store} implementations.
*
* 3. Neither the name of Salesforce.com nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
* @example
* ```
* permuteDomain('foo.bar.example.com')
* // ['example.com', 'bar.example.com', 'foo.bar.example.com']
* ```
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* @public
* @param domain - the domain to generate permutations for
* @param allowSpecialUseDomain - flag to control if {@link https://www.rfc-editor.org/rfc/rfc6761.html | Special Use Domains} such as `localhost` should be allowed
*/
'use strict'
import { getPublicSuffix } from './getPublicSuffix'

// Gives the permutation of all possible domainMatch()es of a given domain. The
// array is in shortest-to-longest order. Handy for indexing.

export function permuteDomain(
domain: string,
allowSpecialUseDomain?: boolean,
Expand Down

0 comments on commit 6400551

Please sign in to comment.