Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenvachon committed Jun 30, 2017
1 parent 6b0260f commit 9c6eb47
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 60 deletions.
61 changes: 3 additions & 58 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,59 +1,4 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
coverage/
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

.nyc_output/
package-lock.json
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- 6
- 8
script: npm test
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
# incomplete-url
Custom-remove features of a WHATWG URL implementation for testing.
# incomplete-url [![NPM Version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]

> Custom-remove features of a WHATWG [`URL`](https://developer.mozilla.org/en/docs/Web/API/URL) implementation.

This is useful when simulating the incomplete `URL` implementations available in some of today's modern web browsers.


## Installation

[Node.js](http://nodejs.org/) `>= 6` is required. To install, type this at the command line:
```shell
npm install incomplete-url
```


## Usage

```js
const customizeURL = require('incomplete-url');

const {IncompleteURL, IncompleteURLSearchParams} = customizeURL(options);

const url = new IncompleteURL('http://domain/');
const params = new IncompleteURLSearchParams('?param=value');
```


## Options

### `noSearchParams`
Type: `Boolean`
Default value: `false`
When set to `true`, the output `URL` class will not expose a `searchParams` property when instantiated.

### `noSort`
Type: `Boolean`
Default value: `false`
When set to `true`, the output `URLSearchParams` class (and `URL#searchParams`) will not expose a `sort` method when instantiated.


[npm-image]: https://img.shields.io/npm/v/incomplete-url.svg
[npm-url]: https://npmjs.org/package/incomplete-url
[travis-image]: https://img.shields.io/travis/stevenvachon/incomplete-url.svg
[travis-url]: https://travis-ci.org/stevenvachon/incomplete-url
91 changes: 91 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"use strict";
const {URL, URLSearchParams} = require("universal-url");



const customizeURL = (options={}) =>
{
const IncompleteURLSearchParams = function(params)
{
this._searchParams = new URLSearchParams(params);

// Support iteration and `Array.from()`
this[Symbol.iterator] = () => this.entries();

this[Symbol.toStringTag] = this._searchParams[Symbol.toStringTag];

// Extend all `URLSearchParams` methods except `sort`
Object.keys(URLSearchParams.prototype)
.filter(key =>
{
if (options.noSort)
{
return key !== "sort";
}
else
{
return true;
}
})
.forEach(key => this[key] = (...args) => this._searchParams[key].call(this._searchParams, ...args));
};

const IncompleteURL = function(url, base)
{
this._url = new URL(url, base);
this._searchParams = new IncompleteURLSearchParams(this._url.search);

this[Symbol.toStringTag] = this._url[Symbol.toStringTag];

// Extend all `URL` getters except perhaps `searchParams`
Object.keys(URL.prototype)
.filter(key =>
{
if (options.noSearchParams)
{
return key !== "searchParams";
}
else
{
return true;
}
})
.forEach(key =>
{
if (key === "searchParams")
{
Object.defineProperty(this, key,
{
get: () => this._searchParams,
set: newValue => this._searchParams = newValue
});
}
else
{
Object.defineProperty(this, key,
{
get: () => this._url[key],
set: newValue =>
{
this._url[key] = newValue;

if (key === "search")
{
this._searchParams = new IncompleteURLSearchParams(newValue);
}
}
});
}
});

//this.search = "";
this.searchParams.append("body", "value")
console.log(Array.from(this.searchParams))
};

return { IncompleteURL, IncompleteURLSearchParams };
};



module.exports = customizeURL;
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "incomplete-url",
"description": "Custom-remove features of a WHATWG URL implementation.",
"version": "0.1.0",
"license": "MIT",
"author": "Steven Vachon <contact@svachon.com> (https://www.svachon.com/)",
"repository": "stevenvachon/incomplete-url",
"dependencies": {
"universal-url": "^1.0.0"
},
"devDependencies": {
"chai": "^4.0.2",
"coveralls": "^2.13.1",
"mocha": "^3.4.2",
"nyc": "^11.0.3"
},
"engines": {
"node": ">= 6"
},
"scripts": {
"ci": "npm run test && nyc report --reporter=text-lcov | coveralls",
"posttest": "nyc report --reporter=html && browserify index.js --global-transform [ babelify --presets [ es2015 ] ] --standalone minURL | uglifyjs --compress --mangle | gzip-size",
"test": "nyc --reporter=text-summary mocha test --check-leaks --bail"
},
"files": [
"index.js"
],
"keywords": [
"uri",
"url",
"whatwg"
]
}
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";
const customizeURL = require("./");
const {expect} = require("chai");
const {it} = require("mocha");



it("noSearchParams = true", function()
{
const options = { noSearchParams:true };
const {IncompleteURL, IncompleteURLSearchParams} = customizeURL(options);

const url = new IncompleteURL("http://hostname?param=value");

expect(url).to.not.have.property("searchParams");
});

0 comments on commit 9c6eb47

Please sign in to comment.