diff --git a/types/adlib/adlib-tests.ts b/types/adlib/adlib-tests.ts new file mode 100644 index 0000000000..e995100a1d --- /dev/null +++ b/types/adlib/adlib-tests.ts @@ -0,0 +1,40 @@ +/* + | Copyright 2018 Esri + | + | Licensed under the Apache License, Version 2.0 (the "License"); + | you may not use this file except in compliance with the License. + | You may obtain a copy of the License at + | + | http://www.apache.org/licenses/LICENSE-2.0 + | + | Unless required by applicable law or agreed to in writing, software + | distributed under the License is distributed on an "AS IS" BASIS, + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + | See the License for the specific language governing permissions and + | limitations under the License. + */ + +import * as adlib from "adlib"; + +const transform1: adlib.TransformFunction = + (key: string, value: any, settings: any, param?: any): any => { + return null; + }; + + const transformsList: adlib.TransformsList = { + firstXform: transform1 +}; + +const template: any = { + value: '{{ instance.color }}' +}; + +const settings: any = { + instance: { + color: 'red' + } +}; + +const interpolated: any = adlib.adlib(template, settings, transformsList); + +const list: string[] = adlib.listDependencies(template); diff --git a/types/adlib/index.d.ts b/types/adlib/index.d.ts new file mode 100644 index 0000000000..8866ab7809 --- /dev/null +++ b/types/adlib/index.d.ts @@ -0,0 +1,75 @@ +// Type definitions for adlib 3.0 +// Project: https://github.com/Esri/adlib +// Definitions by: Esri +// Mike Tschudi +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/* + | Copyright 2018 Esri + | + | Licensed under the Apache License, Version 2.0 (the "License"); + | you may not use this file except in compliance with the License. + | You may obtain a copy of the License at + | + | http://www.apache.org/licenses/LICENSE-2.0 + | + | Unless required by applicable law or agreed to in writing, software + | distributed under the License is distributed on an "AS IS" BASIS, + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + | See the License for the specific language governing permissions and + | limitations under the License. + */ + +/** + * Transform function to apply to interpolated value. + * + * @param key Path within a handlebar-style expression to attempt to replace; e.g., `s.animal.type` in + * https://github.com/Esri/adlib#transforms + * @param value Value to replace expression with + * @param settings Hash providing values to insert into template; see https://github.com/Esri/adlib#general-pattern + * @param param Parameter for transform function; e.g., the `optional` transform accepts a count of levels + * to delete if the value is not found (default is 0--just the current level); + * see https://github.com/Esri/adlib#optional-transform + */ +export interface TransformFunction { + ( + key: string, + value: any, + settings: any, + param?: any + ): any; +} + +/** + * Set of transformation functions keyed by the transform function's name. + */ +export interface TransformsList { + [ transformFnName: string ]: TransformFunction; +} + +/** + * A JavaScript library for interpolating property values in JSON Objects. + * + * @param template A template that possibly containing handlebar-style property values to replace; + * see https://github.com/Esri/adlib#general-pattern + * @param settings Hash providing values to insert into template; see https://github.com/Esri/adlib#general-pattern + * @param transforms Set of transformation functions + * @return Copy of template with replacements performed + */ +export function adlib( + template: any, + settings: any, + transforms?: TransformsList +): any; + +/** + * Reads a template and spits out unique handlebar-style property values. + * + * @param template A template that possibly containing handlebar-style property values to replace; + * see https://github.com/Esri/adlib#general-pattern + * @return List of unique property values in template + */ +export function listDependencies( + template: any +): string []; diff --git a/types/adlib/tsconfig.json b/types/adlib/tsconfig.json new file mode 100644 index 0000000000..570be96b8d --- /dev/null +++ b/types/adlib/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "adlib-tests.ts" + ] +} diff --git a/types/adlib/tslint.json b/types/adlib/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/adlib/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }