mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
feat: Add declarations for andyhu/transliteration (#25542)
* feat(andyhu/transliteration): Add types * Remove unnecessary module declaration * Set tsc strictFunctionTypes to true
This commit is contained in:
committed by
Sheetal Nandi
parent
9617a7fb65
commit
4d232442fa
Vendored
+68
@@ -0,0 +1,68 @@
|
||||
// Type definitions for transliteration 1.6
|
||||
// Project: https://github.com/andyhu/transliteration#readme
|
||||
// Definitions by: Anthony Trinh <https://github.com/tony19>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export function transliterate(str: string, options?: transliterate.Options): string;
|
||||
|
||||
export namespace transliterate {
|
||||
/**
|
||||
* Bind options globally so any following calls will be using
|
||||
* optionsObj by default. If optionsObj argument is omitted,
|
||||
* it will return current default option object.
|
||||
*/
|
||||
function config(optionsObj?: Options): Options;
|
||||
|
||||
interface Options {
|
||||
/**
|
||||
* Unicode characters that are not in the database will be replaced with `unknown`
|
||||
* default: "[?]"
|
||||
*/
|
||||
unknown?: string;
|
||||
|
||||
/**
|
||||
* Custom replacement of the strings before transliteration
|
||||
*/
|
||||
replace?: string[][] | {[source: string]: string};
|
||||
|
||||
/**
|
||||
* Strings in the ignore list will be bypassed from transliteration
|
||||
*/
|
||||
ignore?: string[];
|
||||
}
|
||||
}
|
||||
|
||||
export function slugify(str: string, options?: slugify.Options): string;
|
||||
|
||||
export namespace slugify {
|
||||
/**
|
||||
* Bind options globally so any following calls will be using
|
||||
* optionsObj by default. If optionsObj argument is omitted,
|
||||
* it will return current default option object.
|
||||
*/
|
||||
function config(optionsObj?: Options): Options;
|
||||
|
||||
interface Options {
|
||||
/**
|
||||
* Whether to force slugs to be lowercased
|
||||
* default: true
|
||||
*/
|
||||
lowercase?: boolean;
|
||||
|
||||
/**
|
||||
* Separator of the slug
|
||||
* default: "-"
|
||||
*/
|
||||
separator?: string;
|
||||
|
||||
/**
|
||||
* Custom replacement of the strings before transliteration
|
||||
*/
|
||||
replace?: string[][] | {[source: string]: string};
|
||||
|
||||
/**
|
||||
* Strings in the ignore list will be bypassed from transliteration
|
||||
*/
|
||||
ignore?: string[];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { transliterate as tr, slugify } from 'transliteration';
|
||||
|
||||
tr('你好,世界'); // Ni Hao , Shi Jie
|
||||
tr('Γεια σας, τον κόσμο'); // Geia sas, ton kosmo
|
||||
tr('안녕하세요, 세계'); // annyeonghaseyo, segye
|
||||
tr('你好,世界', { replace: {你: 'You'}, ignore: ['好'] }); // You 好, Shi Jie
|
||||
tr('你好,世界', { replace: [['你', 'You']], ignore: ['好'] }); // You 好, Shi Jie (option in array form)
|
||||
// or use configurations
|
||||
tr.config({ replace: [['你', 'You']], ignore: ['好'] });
|
||||
tr('你好,世界'); // You 好, Shi Jie
|
||||
// get configurations
|
||||
const opt1 = tr.config();
|
||||
opt1.ignore = ['foo', 'bar', 'baz'];
|
||||
opt1.ignore = undefined;
|
||||
opt1.replace = [['a', 'foo'], ['b', 'bar']];
|
||||
opt1.replace = {a: 'foo', b: 'bar', c: 'baz'};
|
||||
opt1.replace = undefined;
|
||||
opt1.unknown = '***?***';
|
||||
opt1.unknown = undefined;
|
||||
|
||||
slugify('你好,世界'); // ni-hao-shi-jie
|
||||
slugify('你好,世界', { lowercase: false, separator: '_' }); // Ni_Hao_Shi_Jie
|
||||
slugify('你好,世界', { replace: {你好: 'Hello', 世界: 'world'}, separator: '_' }); // hello_world
|
||||
slugify('你好,世界', { replace: [['你好', 'Hello'], ['世界', 'world']], separator: '_' }); // hello_world (option in array form)
|
||||
slugify('你好,世界', { ignore: ['你好'] }); // 你好shi-jie
|
||||
// or use configurations
|
||||
slugify.config({ lowercase: false, separator: '_' });
|
||||
slugify('你好,世界'); // Ni_Hao_Shi_Jie
|
||||
// get configurations
|
||||
const opt2 = slugify.config();
|
||||
opt2.ignore = ['foo', 'bar', 'baz'];
|
||||
opt2.ignore = undefined;
|
||||
opt2.replace = [['a', 'foo'], ['b', 'bar']];
|
||||
opt2.replace = {a: 'foo', b: 'bar', c: 'baz'};
|
||||
opt2.replace = undefined;
|
||||
opt2.lowercase = false;
|
||||
opt2.lowercase = true;
|
||||
opt2.lowercase = undefined;
|
||||
opt2.separator = ';';
|
||||
opt2.separator = undefined;
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es5"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"transliteration-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user