Add types for php-serialize (#40869)

* Add type definitions for 'php-serialize'

* Modifying tscconfig.json to the guidelines

* Add missing type definitions header

* Add test file into tsconfig

* Fix typing and remove unused variable declaration

* Fix optional function parameters

* Add empty line for linter

* Update types/php-serialize/index.d.ts

Co-Authored-By: Dmitry Demensky <10235949+demensky@users.noreply.github.com>

* Update types/php-serialize/index.d.ts

Co-Authored-By: Dmitry Demensky <10235949+demensky@users.noreply.github.com>

* Update types/php-serialize/index.d.ts

Co-Authored-By: Dmitry Demensky <10235949+demensky@users.noreply.github.com>

* Update index.d.ts

* Update tsconfig.json

* Revert tsconfig.json chnages

* Add reference types header for node

Co-authored-by: Dmitry Demensky <10235949+demensky@users.noreply.github.com>
This commit is contained in:
Changhui Lee 2019-12-27 05:32:52 +09:00 committed by Andrew Branch
parent b6a418b05f
commit e665d7c49f
4 changed files with 60 additions and 0 deletions

25
types/php-serialize/index.d.ts vendored Normal file
View File

@ -0,0 +1,25 @@
// Type definitions for php-serialize 3.0
// Project: https://github.com/steelbrain/php-serialize
// Definitions by: Changhui Lee <https://github.com/blurfx>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.7
/// <reference types="node" />
export interface SerializeOptions {
/** @default 'utf8' */
readonly encoding?: 'utf8' | 'binary';
}
export interface UnserializeOptions {
/** @default true' */
readonly strict?: boolean;
/** @default 'utf8' */
readonly encoding?: 'utf8' | 'binary';
}
export function isSerialized(givenItem: any, strict?: boolean): boolean;
export function serialize(item: any, scope?: any, givenOptions?: SerializeOptions): string;
export function unserialize(item: string | Buffer, scope?: any, givenOptions?: UnserializeOptions): any;

View File

@ -0,0 +1,8 @@
import PhpSerialize = require('php-serialize');
const testObject = {
user_id: 399,
parent_user_id: 399,
};
const serialized = PhpSerialize.serialize(testObject);
PhpSerialize.unserialize(serialized);

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"php-serialize-tests.ts"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}