php-serialize
Advanced tools
Comparing version 4.1.1 to 5.0.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getClass = exports.getIncompleteClass = exports.isInteger = exports.getByteLength = exports.__PHP_Incomplete_Class = void 0; | ||
exports.invariant = exports.getClass = exports.getIncompleteClass = exports.isInteger = exports.getByteLength = exports.__PHP_Incomplete_Class = void 0; | ||
// eslint-disable-next-line camelcase,@typescript-eslint/class-name-casing | ||
@@ -21,3 +21,3 @@ var __PHP_Incomplete_Class = /** @class */ (function () { | ||
function isInteger(value) { | ||
return typeof value === 'number' && parseInt(value.toString(), 10) === value; | ||
return typeof value === 'number' && Number.parseInt(value.toString(), 10) === value; | ||
} | ||
@@ -37,1 +37,12 @@ exports.isInteger = isInteger; | ||
exports.getClass = getClass; | ||
/** | ||
* Ensures that the given {@link value} is truthy, throws an {@link Error} otherwise. | ||
* @param value the value to check to be truthy. | ||
* @param message the message of the {@link Error} if the value is falsy. | ||
*/ | ||
function invariant(value, message) { | ||
if (!value) { | ||
throw new Error(message); | ||
} | ||
} | ||
exports.invariant = invariant; |
@@ -56,2 +56,3 @@ "use strict"; | ||
} | ||
break; | ||
// or else fall through | ||
@@ -58,0 +59,0 @@ case 'a': |
@@ -76,3 +76,3 @@ "use strict"; | ||
Parser.prototype.getLength = function () { | ||
var length = parseInt(this.readUntil(':'), 10); | ||
var length = Number.parseInt(this.readUntil(':'), 10); | ||
if (Number.isNaN(length)) { | ||
@@ -79,0 +79,0 @@ throw this.error(); |
@@ -29,7 +29,3 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var assert_1 = __importDefault(require("assert")); | ||
var helpers_1 = require("./helpers"); | ||
@@ -76,6 +72,8 @@ function getClassNamespace(item, scope) { | ||
if (item instanceof Map) { | ||
return "a:" + item.size + ":{" + Array.from(item.entries()).map(function (_a) { | ||
return "a:" + item.size + ":{" + Array.from(item.entries()) | ||
.map(function (_a) { | ||
var _b = __read(_a, 2), key = _b[0], value = _b[1]; | ||
return "" + serialize(key, scope) + serialize(value, scope); | ||
}).join('') + "}"; | ||
}) | ||
.join('') + "}"; | ||
} | ||
@@ -85,3 +83,3 @@ var constructorName = getClassNamespace(item, scope); | ||
var serialized = item.serialize(); | ||
assert_1.default(typeof serialized === 'string', item.constructor.name + ".serialize should return a string"); | ||
helpers_1.invariant(typeof serialized === 'string', item.constructor.name + ".serialize should return a string"); | ||
return "C:" + constructorName.length + ":\"" + constructorName + "\":" + helpers_1.getByteLength(serialized, options) + ":{" + serialized + "}"; | ||
@@ -88,0 +86,0 @@ } |
@@ -17,3 +17,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var assert_1 = __importDefault(require("assert")); | ||
// eslint-disable-next-line import/no-cycle | ||
@@ -25,3 +24,3 @@ var parser_1 = __importDefault(require("./parser")); | ||
var classReference = scope[className]; | ||
assert_1.default(classReference || !strict, "Class " + className + " not found in given scope"); | ||
helpers_1.invariant(classReference || !strict, "Class " + className + " not found in given scope"); | ||
if (classReference) { | ||
@@ -104,3 +103,3 @@ // @ts-ignore | ||
if (!(result instanceof helpers_1.__PHP_Incomplete_Class)) { | ||
assert_1.default(result.unserialize, "unserialize not found on class when processing '" + name + "'"); | ||
helpers_1.invariant(result.unserialize, "unserialize not found on class when processing '" + name + "'"); | ||
result.unserialize(payload); | ||
@@ -107,0 +106,0 @@ } |
@@ -17,3 +17,3 @@ // eslint-disable-next-line camelcase,@typescript-eslint/class-name-casing | ||
export function isInteger(value) { | ||
return typeof value === 'number' && parseInt(value.toString(), 10) === value; | ||
return typeof value === 'number' && Number.parseInt(value.toString(), 10) === value; | ||
} | ||
@@ -30,1 +30,11 @@ export function getIncompleteClass(name) { | ||
} | ||
/** | ||
* Ensures that the given {@link value} is truthy, throws an {@link Error} otherwise. | ||
* @param value the value to check to be truthy. | ||
* @param message the message of the {@link Error} if the value is falsy. | ||
*/ | ||
export function invariant(value, message) { | ||
if (!value) { | ||
throw new Error(message); | ||
} | ||
} |
@@ -54,2 +54,3 @@ /** | ||
} | ||
break; | ||
// or else fall through | ||
@@ -56,0 +57,0 @@ case 'a': |
@@ -74,3 +74,3 @@ var __read = (this && this.__read) || function (o, n) { | ||
Parser.prototype.getLength = function () { | ||
var length = parseInt(this.readUntil(':'), 10); | ||
var length = Number.parseInt(this.readUntil(':'), 10); | ||
if (Number.isNaN(length)) { | ||
@@ -77,0 +77,0 @@ throw this.error(); |
@@ -28,4 +28,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import invariant from 'assert'; | ||
import { isInteger, getByteLength } from './helpers'; | ||
import { isInteger, getByteLength, invariant } from './helpers'; | ||
function getClassNamespace(item, scope) { | ||
@@ -71,6 +70,8 @@ return (Object.keys(scope).find(function (key) { return item instanceof scope[key]; }) || item.__PHP_Incomplete_Class_Name || item.constructor.name); | ||
if (item instanceof Map) { | ||
return "a:" + item.size + ":{" + Array.from(item.entries()).map(function (_a) { | ||
return "a:" + item.size + ":{" + Array.from(item.entries()) | ||
.map(function (_a) { | ||
var _b = __read(_a, 2), key = _b[0], value = _b[1]; | ||
return "" + serialize(key, scope) + serialize(value, scope); | ||
}).join('') + "}"; | ||
}) | ||
.join('') + "}"; | ||
} | ||
@@ -77,0 +78,0 @@ var constructorName = getClassNamespace(item, scope); |
@@ -12,6 +12,5 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import invariant from 'assert'; | ||
// eslint-disable-next-line import/no-cycle | ||
import Parser from './parser'; | ||
import { isInteger, getClass, getIncompleteClass, __PHP_Incomplete_Class } from './helpers'; | ||
import { isInteger, getClass, getIncompleteClass, __PHP_Incomplete_Class, invariant } from './helpers'; | ||
function getClassReference(className, scope, strict) { | ||
@@ -18,0 +17,0 @@ var container; |
@@ -15,1 +15,7 @@ /// <reference types="node" /> | ||
}; | ||
/** | ||
* Ensures that the given {@link value} is truthy, throws an {@link Error} otherwise. | ||
* @param value the value to check to be truthy. | ||
* @param message the message of the {@link Error} if the value is falsy. | ||
*/ | ||
export declare function invariant(value: any, message?: string): void; |
/// <reference types="node" /> | ||
import { Options } from './unserialize'; | ||
import type { Options } from './unserialize'; | ||
export declare type ParserType = 'null' | 'int' | 'float' | 'boolean' | 'string' | 'array-object' | 'serializable-class' | 'notserializable-class'; | ||
@@ -4,0 +4,0 @@ export default class Parser { |
{ | ||
"name": "php-serialize", | ||
"version": "4.1.1", | ||
"version": "5.0.0", | ||
"description": "PHP serialize/unserialize in Javascript", | ||
@@ -51,3 +51,4 @@ "main": "lib/cjs/index.js", | ||
"node": ">= 8" | ||
} | ||
}, | ||
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
} |
@@ -5,2 +5,11 @@ # PHP-Serialize | ||
#### Installation | ||
```sh | ||
$ npm install php-serialize # If you're using npm | ||
$ yarn add php-serialize # If you're using Yarn | ||
``` | ||
#### Usage | ||
```js | ||
@@ -7,0 +16,0 @@ import {serialize, unserialize} from 'php-serialize' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36884
880
64