Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript definition #23

Merged
merged 2 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.4.2",
"description": "Immutability helpers with fast reads and acceptable writes",
"main": "lib/timm.js",
"types": "lib/timm.d.ts",
"dependencies": {},
"devDependencies": {
"ava": "0.16.0",
Expand Down Expand Up @@ -48,7 +49,7 @@
"testCovProd": "cross-env NODE_ENV=production nyc ava && mv .nyc_output/* .nyc_tmp/",
"testCovMin": "cross-env TEST_MINIFIED_LIB=1 nyc ava && mv .nyc_output/* .nyc_tmp/",
"testCovReport": "cp .nyc_tmp/* .nyc_output/ && nyc report --reporter=html --reporter=lcov",
"compile": "rm -rf ./lib && mkdir lib && babel -o lib/timm.js src/timm.js && cp src/api.js.flow lib/timm.js.flow",
"compile": "rm -rf ./lib && mkdir lib && babel -o lib/timm.js src/timm.js && cp src/api.js.flow lib/timm.js.flow && cp src/timm.d.ts lib/timm.d.ts",
"docs": "extract-docs --template docs/README_TEMPLATE.md --output README.md",
"uglify": "cross-env NODE_ENV=production envify lib/timm.js | uglifyjs - -o lib/timm.min.js --mangle --compress --comments \"/^!/\"",
"build": "yarn lint && yarn flow && yarn compile && yarn uglify && yarn testCovFull && yarn docs && yarn xxl",
Expand Down
72 changes: 72 additions & 0 deletions src/timm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
declare module 'timm' {
type ArrayOrObject = Array<any> | Object;
type Key = number | string;

export function clone<T = ArrayOrObject> (obj: T): T
export function addLast<T> (array: Array<T>, val: Array<T> | T): Array<T>
export function addFirst<T> (array: Array<T>, val: Array<T> | T): Array<T>
export function removeLast<T> (array: Array<T>): Array<T>
export function removeFirst<T> (array: Array<T>): Array<T>
export function insert<T>(
array: Array<T>,
idx: number,
val: Array<T> | T
): Array<T>
export function removeAt<T> (array: Array<T>, idx: number): Array<T>
export function replaceAt<T>(
array: Array<T>,
idx: number,
newItem: T
): Array<T>
export function getIn(obj: ArrayOrObject | undefined, path: Array<Key>): any
export function set<T> (obj: T | undefined, key: Key, val: any): T
export function setIn<T = ArrayOrObject> (obj: T, path: Array<Key>, val: any): T
export function update<T = ArrayOrObject> (
obj: T,
key: Key,
fnUpdate: (prevValue: any) => any
): T
export function updateIn<T = ArrayOrObject> (
obj: T,
path: Array<Key>,
fnUpdate: (prevValue: any) => any
): T
export function merge(
a: Object,
b?: Object,
c?: Object,
d?: Object,
e?: Object,
f?: Object,
...rest: Array<Object>
): Object
export function mergeDeep(
a: Object,
b?: Object,
c?: Object,
d?: Object,
e?: Object,
f?: Object,
...rest: Array<Object>
): Object
export function mergeIn<T = ArrayOrObject> (
a: T,
path: Array<Key>,
b?: Object,
c?: Object,
d?: Object,
e?: Object,
f?: Object,
...rest: Array<Object>
): T
export function omit(obj: Object, attrs: Array<string> | string): Object
export function addDefaults(
a: Object,
b?: Object,
c?: Object,
d?: Object,
e?: Object,
f?: Object,
...rest: Array<Object>
): Object
}