Neptune's Potato Monsters

    url-path-object
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.2 • Public • Published

    URL-Path-Object

    This Angular Module allows you to create a URL Path object that can be modified and outputs back into a url path.

    Installation

    npm install url-path-object
    

    Scaffolding

    Import the module into your project under imports

    imports: [
        BrowserModule,
        AppRoutingModule,
        UrlPathObjectModule
      ],
    

    Use

    In your component file, import the module in the constructor

    private urlObject: UrlPathObject
    

    Then call any of the functions, like the eample below

    const urlObj = this.urlObject.init(urlPath)
    urlObj.setDomain('www.artreaction.ca')
    

    Here is a sample of a component setup

    export class AppComponent implements OnInit {
    
      constructor(
        private urlObject: UrlPathObject
        ) {}
    
      ngOnInit() {
    
        const urlPath = "https://www.npmjs.com:8500/settings/wavecoders/packages"
    
        const urlObj = this.urlObject.init(urlPath)
        console.log(urlObj.data)
    
        urlObj.setDomain('www.artreaction.ca')
        urlObj.setPort(4400)
    
        urlObj.addQueryParam('sample', '123')
        urlObj.updateQueryParam('sample', 'abc')
        urlObj.deleteQueryParam('sample')
    
        const newUrlPath = urlObj.getPath()
        console.log(newUrlPath)
    
      }
    
    }
    

    Sample

    const urlPath0 = "Users/mike.boni/Desktop"
    const urlPath1 = "Users/mike.boni/Desktop/test.html"
    const urlPath2 = "file:///Users/mike.boni/Desktop/mame-box.ai"
    const urlPath3 = "https://www.npmjs.com/settings/wavecoders/packages/index.html"
    const urlPath4 = "https://www.npmjs.com:8500/settings/wavecoders/packages"
    const urlPath5 = "https://wavecoders.atlassian.net:8500/jira1/c/projects123/TN/boards/3?selectedIssue=123-425&user=mike%20boni"
    
    const urlObj = this.urlObject.init(urlPath5)
    console.log(urlObj.data)
    
    urlObj.setDomain('www.artreaction.ca')
    urlObj.setPort(4400)
    
    urlObj.addQueryParam('sample', '123')
    
    // urlObj.updateQueryParam('sample', 'abc')
    // console.log(urlObj.data)
    
    // urlObj.deleteQueryParam('sample')
    // console.log(urlObj.data)
    
    console.log(urlObj.getPath())
    

    Returns

    {
        "host": "artreaction.ca:8500",
        "pathname": "/jira/software/c/projects/GA/boards/3",
        "port": "8500",
        "protocol": "https:",
        "hostname": "artreaction.ca:8500",
        "search": "?selectedIssue=GA-425&user=mike%20boni&sample=123",
        "query": {
            "selectedIssue": "GA-425",
            "user": "mike boni",
            "sample": "123"
        },
        "origin": "https://artreaction.ca:8500",
        "file": {
            "origin": "jira",
            "path": "/software/c/projects/GA/boards/3",
            "file": "",
            "fileName": "",
            "ext": ""
        },
        "domain": {
            "domain": "artreaction.ca",
            "subdomain": "",
            "domainName": "artreaction",
            "network": "ca"
        }
    }
    

    Install

    npm i url-path-object

    DownloadsWeekly Downloads

    1

    Version

    2.0.2

    License

    ISC

    Unpacked Size

    155 kB

    Total Files

    32

    Last publish

    Collaborators

    • wavecoders