mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 14:38:20 +08:00
Complete definition for js-base64 and update to version 2.3 (#20929)
* Update version number * Format existing code * Add name to authors * Add tslint.json * Rewrite to match module.d.ts template * Add missing functions * Add extendString and related String augmentation * Correct uriSafe parameter to be optional * Correct extended functions to be required * Add new tests and fix global Base64 * Add missing uriSafe parameter to toBase64 * Enable strictNullChecks * Add missing test case
This commit is contained in:
committed by
Sheetal Nandi
parent
862fb26137
commit
2b42a4123b
81
types/js-base64/index.d.ts
vendored
81
types/js-base64/index.d.ts
vendored
@@ -1,54 +1,45 @@
|
||||
// Type definitions for js-base64 v2.1.9
|
||||
// Type definitions for js-base64 2.3
|
||||
// Project: https://github.com/dankogai/js-base64
|
||||
// Definitions by: Denis Carriere <https://github.com/DenisCarriere>
|
||||
// Definitions by: Denis Carriere <https://github.com/DenisCarriere>, Tommy Lent <https://github.com/tlent>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
## TODO
|
||||
export namespace Base64 {
|
||||
const VERSION: string;
|
||||
|
||||
add methods:
|
||||
- [x] encode
|
||||
- [x] encodeURI
|
||||
- [x] decode
|
||||
- [ ] atob
|
||||
- [ ] btoa
|
||||
- [ ] fromBase64
|
||||
- [ ] toBase64
|
||||
- [ ] utob
|
||||
- [ ] btou
|
||||
- [ ] noConflict
|
||||
*/
|
||||
function encode(s: string, uriSafe?: boolean): string;
|
||||
|
||||
declare module 'js-base64' {
|
||||
namespace JSBase64 {
|
||||
const Base64: Base64Static
|
||||
interface Base64Static {
|
||||
/**
|
||||
* .encode
|
||||
* @param {String} string
|
||||
* @return {String}
|
||||
*/
|
||||
encode(base64: string): string;
|
||||
function encodeURI(s: string): string;
|
||||
|
||||
/**
|
||||
* .encodeURI
|
||||
* @param {String} string
|
||||
* @return {String}
|
||||
*/
|
||||
encodeURI(base64: string): string
|
||||
function decode(base64: string): string;
|
||||
|
||||
/**
|
||||
* .decode
|
||||
* @param {String} string
|
||||
* @return {String}
|
||||
*/
|
||||
decode(base64: string): string
|
||||
function atob(base64: string): string;
|
||||
|
||||
/**
|
||||
* Library version
|
||||
*/
|
||||
VERSION:string
|
||||
}
|
||||
}
|
||||
export = JSBase64
|
||||
function btoa(s: string): string;
|
||||
|
||||
function fromBase64(base64: string): string;
|
||||
|
||||
function toBase64(s: string, uriSafe?: boolean): string;
|
||||
|
||||
function btou(s: string): string;
|
||||
|
||||
function utob(s: string): string;
|
||||
|
||||
function noConflict(): typeof Base64;
|
||||
|
||||
function extendString(): void;
|
||||
}
|
||||
|
||||
// Helper to allow referencing Base64 from inside the global declaration without creating a self reference
|
||||
/* tslint:disable:strict-export-declare-modifiers */
|
||||
type Base64_ = typeof Base64;
|
||||
/* tslint:enable:strict-export-declare-modifiers */
|
||||
|
||||
declare global {
|
||||
interface String {
|
||||
fromBase64(): string;
|
||||
toBase64(uriSafe?: boolean): string;
|
||||
toBase64URI(): string;
|
||||
}
|
||||
|
||||
const Base64: Base64_;
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Base64 } from 'js-base64'
|
||||
|
||||
Base64.encode('dankogai'); // ZGFua29nYWk=
|
||||
Base64.encode('小飼弾'); // 5bCP6aO85by+
|
||||
Base64.encodeURI('小飼弾'); // 5bCP6aO85by-
|
||||
|
||||
Base64.decode('ZGFua29nYWk='); // dankogai
|
||||
Base64.decode('5bCP6aO85by+'); // 小飼弾
|
||||
// note .decodeURI() is unnecessary since it accepts both flavors
|
||||
Base64.decode('5bCP6aO85by-'); // 小飼弾
|
||||
19
types/js-base64/test/js-base64-global.test.ts
Normal file
19
types/js-base64/test/js-base64-global.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
Base64.encode(''); // $ExpectType string
|
||||
Base64.encode('', true); // $ExpectType string
|
||||
Base64.encodeURI(''); // $ExpectType string
|
||||
Base64.decode(''); // $ExpectType string
|
||||
Base64.atob(''); // $ExpectType string
|
||||
Base64.btoa(''); // $ExpectType string
|
||||
Base64.fromBase64(''); // $ExpectType string
|
||||
Base64.toBase64(''); // $ExpectType string
|
||||
Base64.toBase64('', true); // $ExpectType string
|
||||
Base64.btou(''); // $ExpectType string
|
||||
Base64.utob(''); // $ExpectType string
|
||||
|
||||
Base64.noConflict(); // $ExpectType typeof Base64
|
||||
|
||||
Base64.extendString(); // $ExpectType void
|
||||
''.toBase64(); // $ExpectType string
|
||||
''.toBase64(true); // $ExpectType string
|
||||
''.toBase64URI(); // $ExpectType string
|
||||
''.fromBase64(); // $ExpectType string
|
||||
21
types/js-base64/test/js-base64-module.test.ts
Normal file
21
types/js-base64/test/js-base64-module.test.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Base64 } from 'js-base64';
|
||||
|
||||
Base64.encode(''); // $ExpectType string
|
||||
Base64.encode('', true); // $ExpectType string
|
||||
Base64.encodeURI(''); // $ExpectType string
|
||||
Base64.decode(''); // $ExpectType string
|
||||
Base64.atob(''); // $ExpectType string
|
||||
Base64.btoa(''); // $ExpectType string
|
||||
Base64.fromBase64(''); // $ExpectType string
|
||||
Base64.toBase64(''); // $ExpectType string
|
||||
Base64.toBase64('', true); // $ExpectType string
|
||||
Base64.btou(''); // $ExpectType string
|
||||
Base64.utob(''); // $ExpectType string
|
||||
|
||||
Base64.noConflict(); // $ExpectType typeof Base64
|
||||
|
||||
Base64.extendString(); // $ExpectType void
|
||||
''.toBase64(); // $ExpectType string
|
||||
''.toBase64(true); // $ExpectType string
|
||||
''.toBase64URI(); // $ExpectType string
|
||||
''.fromBase64(); // $ExpectType string
|
||||
@@ -1,23 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"js-base64-tests.ts"
|
||||
"test/js-base64-module.test.ts",
|
||||
"test/js-base64-global.test.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
3
types/js-base64/tslint.json
Normal file
3
types/js-base64/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user