New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

phpurlencode

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phpurlencode - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

14

index.js

@@ -18,18 +18,4 @@ "use strict";

const definePrototypes = function () {
if (!String.prototype.urlencode) {
global.String.prototype.urlencode = function () {
return encode(this);
};
}
if (!String.prototype.urldecode) {
global.String.prototype.urldecode = function () {
return decode(this);
};
}
};
module.exports = encode;
module.exports.encode = encode;
module.exports.decode = decode;
module.exports.definePrototypes = definePrototypes;

2

package.json
{
"name": "phpurlencode",
"description": "Functionally similar to PHP urlencode and urldecode functions",
"version": "1.0.3",
"version": "1.0.4",
"main": "index.js",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -18,10 +18,5 @@ # phpurlencode

### Include it in your Node.js file
### phpurlencode(string)
```js
var phpurlencode = require('phpurlencode');
```
### phpurlencode(string)
```js
var encodedString = phpurlencode("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.67 Safari/537.36");

@@ -45,17 +40,1 @@ console.log(encodedString);

```
### phpurlencode.definePrototypes()
#### Globally defines `.urlencode` and `.urldecode` String prototypes
```js
// Register String prototypes.
// Once this function is called, the String prototypes will be available across your entire project
phpurlencode.definePrototypes();
var decodedString = '%21%40%23%24%25%5E%26%2A%28%29-%2B%3D%27%22'.urldecode();
console.log(decodedString);
// => !@#$%^&*()-+='"
var encodedString = decodedString.urlencode();
console.log(encodedString);
// => %21%40%23%24%25%5E%26%2A%28%29-%2B%3D%27%22
```

@@ -5,13 +5,2 @@ "use strict";

const strings = {
userAgent: {
encoded: "Mozilla%2F5.0+%28Macintosh%3B+Intel+Mac+OS+X+10_12_2%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F56.0.2924.67+Safari%2F537.36",
decoded: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.67 Safari/537.36"
},
specialChars: {
encoded: "%21%40%23%24%25%5E%26%2A%28%29%2B%27%7E%22%3C%3E%2C.",
decoded: "!@#$%^&*()+'~\"<>,."
}
};
describe("urlencode", function() {

@@ -23,4 +12,4 @@ describe("#encode()", function() {

assert.equal(
strings.specialChars.encoded,
urlencode(strings.specialChars.decoded)
"%21%40%23%24%25%5E%26%2A%28%29%2B%27%7E%22%3C%3E%2C.",
urlencode("!@#$%^&*()+'~\"<>,.")
);

@@ -31,4 +20,6 @@ }

assert.equal(
strings.userAgent.encoded,
urlencode.encode(strings.userAgent.decoded)
"Mozilla%2F5.0+%28Macintosh%3B+Intel+Mac+OS+X+10_12_2%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F56.0.2924.67+Safari%2F537.36",
urlencode.encode(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.67 Safari/537.36"
)
);

@@ -43,4 +34,4 @@ });

assert.equal(
strings.specialChars.decoded,
urlencode.decode(strings.specialChars.encoded)
"!@#$%^&*()+'~\"<>,.",
urlencode.decode("%21%40%23%24%25%5E%26%2A%28%29%2B%27%7E%22%3C%3E%2C.")
);

@@ -51,4 +42,6 @@ }

assert.equal(
strings.userAgent.decoded,
urlencode.decode(strings.userAgent.encoded)
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.67 Safari/537.36",
urlencode.decode(
"Mozilla%2F5.0+%28Macintosh%3B+Intel+Mac+OS+X+10_12_2%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F56.0.2924.67+Safari%2F537.36"
)
);

@@ -58,35 +51,1 @@ });

});
describe("#definePrototypes()", function () {
it("should register global String prototypes", function () {
urlencode.definePrototypes();
assert.equal(false, !String.prototype.urldecode, 'String.prototype.urldecode exists');
assert.equal(false, !String.prototype.urlencode, 'String.prototype.urlencode exists');
});
it("should correctly encode with String prototype", function () {
assert.equal(
strings.specialChars.decoded.urlencode(),
strings.specialChars.encoded,
'correctly encodes special character test string'
);
assert.equal(
strings.userAgent.decoded.urlencode(),
strings.userAgent.encoded,
'correctly encodes user-agent test string'
);
});
it("should correctly decode with String prototype", function () {
assert.equal(
strings.specialChars.encoded.urldecode(),
strings.specialChars.decoded,
'correctly decodes special character test string'
);
assert.equal(
strings.userAgent.encoded.urldecode(),
strings.userAgent.decoded,
'correctly decodes user-agent test string'
);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc