Skip to content

Commit 8aeef4a

Browse files
committed
typescript support
1 parent 78f3b86 commit 8aeef4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2645
-142
lines changed

constants/supportedTransforms.js

Lines changed: 0 additions & 59 deletions
This file was deleted.

dist/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Lines changed: 64 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,178 +1,166 @@
1+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
2+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
3+
to[j] = from[i];
4+
return to;
5+
};
16
/*
27
Helper Modules
38
*/
49
var _ = require('lodash');
5-
610
/*
711
Implementations
812
*/
913
var url = require('./libs/url');
1014
var upload = require('./libs/upload');
1115
var manage = require('./libs/manage');
1216
var signature = require('./libs/signature');
13-
1417
/*
1518
Utils
1619
*/
1720
var pHashUtils = require('./utils/phash');
1821
var transformationUtils = require('./utils/transformation');
1922
var errorMessages = require("./constants/errorMessages");
20-
21-
var ImageKit = function(opts) {
23+
var ImageKit = function (opts) {
2224
opts = opts || {};
2325
this.options = {
24-
publicKey : "",
25-
privateKey : "",
26-
urlEndpoint : "",
27-
transformationPosition : transformationUtils.getDefault()
26+
publicKey: "",
27+
privateKey: "",
28+
urlEndpoint: "",
29+
transformationPosition: transformationUtils.getDefault()
2830
};
29-
3031
this.options = _.extend(this.options, opts);
31-
if(!this.options.publicKey) {
32+
if (!this.options.publicKey) {
3233
throw new Error(errorMessages.MANDATORY_PUBLIC_KEY_MISSING.message);
3334
}
34-
if(!this.options.privateKey) {
35+
if (!this.options.privateKey) {
3536
throw new Error(errorMessages.MANDATORY_PRIVATE_KEY_MISSING.message);
3637
}
37-
if(!this.options.urlEndpoint) {
38+
if (!this.options.urlEndpoint) {
3839
throw new Error(errorMessages.MANDATORY_URL_ENDPOINT_KEY_MISSING.message);
3940
}
40-
41-
const promisify = function(f) {
42-
return function(...args) {
43-
const self = this;
41+
var promisify = function (f) {
42+
return function () {
43+
var args = [];
44+
for (var _i = 0; _i < arguments.length; _i++) {
45+
args[_i] = arguments[_i];
46+
}
47+
var self = this;
4448
if (args.length === f.length) {
45-
if (typeof args[args.length-1] !== 'function') {
46-
throw new Error('Callback must be a function.')
49+
if (typeof args[args.length - 1] !== 'function') {
50+
throw new Error('Callback must be a function.');
4751
}
48-
f.call(self, ...args)
49-
} else {
50-
return new Promise((resolve, reject) => {
51-
const callback = function(err, ...results) {
52+
f.call.apply(f, __spreadArray([self], args));
53+
}
54+
else {
55+
return new Promise(function (resolve, reject) {
56+
var callback = function (err) {
57+
var results = [];
58+
for (var _i = 1; _i < arguments.length; _i++) {
59+
results[_i - 1] = arguments[_i];
60+
}
5261
if (err) {
5362
return reject(err);
54-
} else {
55-
resolve(results.length > 1 ? results : results[0])
5663
}
57-
}
64+
else {
65+
resolve(results.length > 1 ? results : results[0]);
66+
}
67+
};
5868
args.push(callback);
59-
f.call(self, ...args);
69+
f.call.apply(f, __spreadArray([self], args));
6070
});
6171
}
62-
}
63-
}
64-
72+
};
73+
};
6574
/*
6675
URL Builder
6776
*/
68-
this.url = function(urlOptions) {
77+
this.url = function (urlOptions) {
6978
return url(urlOptions, this.options);
7079
};
71-
7280
/*
7381
Upload API
7482
*/
75-
this.upload = promisify(function(uploadOptions, callback) {
83+
this.upload = promisify(function (uploadOptions, callback) {
7684
return upload(uploadOptions, this.options, callback);
7785
});
78-
7986
/*
8087
Image Management APIs
8188
*/
82-
8389
// List and Search Files API
84-
this.listFiles = promisify(function(listOptions, callback) {
90+
this.listFiles = promisify(function (listOptions, callback) {
8591
return manage.listFiles(listOptions, this.options, callback);
8692
});
87-
8893
// Get File Details API
89-
this.getFileDetails = promisify(function(fileId, callback) {
94+
this.getFileDetails = promisify(function (fileId, callback) {
9095
return manage.getFileDetails(fileId, this.options, callback);
9196
});
92-
9397
// Get File Metadata API
94-
this.getFileMetadata = promisify(function(fileId, callback) {
98+
this.getFileMetadata = promisify(function (fileId, callback) {
9599
return manage.getFileMetadata(fileId, this.options, callback);
96100
});
97-
98101
// Update File Details API
99-
this.updateFileDetails = promisify(function(fileId, updateData, callback) {
102+
this.updateFileDetails = promisify(function (fileId, updateData, callback) {
100103
return manage.updateFileDetails(fileId, updateData, this.options, callback);
101104
});
102-
103105
// Add bulk tags
104-
this.bulkAddTags = promisify(function(fileIdArray, tags, callback) {
105-
return manage.bulkAddTags(fileIdArray, tags, this.options, callback);
106+
this.bulkAddTags = promisify(function (fileIds, tags, callback) {
107+
return manage.bulkAddTags(fileIds, tags, this.options, callback);
106108
});
107-
108109
// Remove bulk tags
109-
this.bulkRemoveTags = promisify(function(fileIds, tags, callback) {
110+
this.bulkRemoveTags = promisify(function (fileIds, tags, callback) {
110111
return manage.bulkRemoveTags(fileIds, tags, this.options, callback);
111112
});
112-
113113
// Delete File API
114-
this.deleteFile = promisify(function(fileId, callback) {
114+
this.deleteFile = promisify(function (fileId, callback) {
115115
return manage.deleteFile(fileId, this.options, callback);
116116
});
117-
118117
// Purge Cache API
119-
this.purgeCache = promisify(function(url, callback) {
118+
this.purgeCache = promisify(function (url, callback) {
120119
return manage.purgeCache(url, this.options, callback);
121120
});
122-
123121
// Purge Cache Status API
124-
this.getPurgeCacheStatus = promisify(function(requestId, callback) {
122+
this.getPurgeCacheStatus = promisify(function (requestId, callback) {
125123
return manage.getPurgeCacheStatus(requestId, this.options, callback);
126124
});
127-
128-
this.bulkDeleteFiles = promisify(function(fileIdArray, callback) {
125+
this.bulkDeleteFiles = promisify(function (fileIdArray, callback) {
129126
return manage.bulkDeleteFiles(fileIdArray, this.options, callback);
130127
});
131-
132128
// Copy files API
133-
this.copyFile = promisify(function(sourceFilePath, destinationPath, callback) {
129+
this.copyFile = promisify(function (sourceFilePath, destinationPath, callback) {
134130
return manage.copyFile(sourceFilePath, destinationPath, this.options, callback);
135131
});
136-
137132
// Move files API
138-
this.moveFile = promisify(function(sourceFilePath, destinationPath, callback) {
133+
this.moveFile = promisify(function (sourceFilePath, destinationPath, callback) {
139134
return manage.moveFile(sourceFilePath, destinationPath, this.options, callback);
140135
});
141-
142136
// Create folder API
143-
this.createFolder = promisify(function(folderName, parentFolderPath, callback) {
137+
this.createFolder = promisify(function (folderName, parentFolderPath, callback) {
144138
return manage.createFolder(folderName, parentFolderPath, this.options, callback);
145139
});
146-
147140
// Delete folder API
148-
this.deleteFolder = promisify(function(folderPath, callback) {
141+
this.deleteFolder = promisify(function (folderPath, callback) {
149142
return manage.deleteFolder(folderPath, this.options, callback);
150143
});
151-
152144
// Copy folder API
153-
this.copyFolder = promisify(function(sourceFolderPath, destinationPath, callback) {
145+
this.copyFolder = promisify(function (sourceFolderPath, destinationPath, callback) {
154146
return manage.copyFolder(sourceFolderPath, destinationPath, this.options, callback);
155147
});
156-
157148
// Move folder API
158-
this.moveFolder = promisify(function(sourceFolderPath, destinationPath, callback) {
149+
this.moveFolder = promisify(function (sourceFolderPath, destinationPath, callback) {
159150
return manage.moveFolder(sourceFolderPath, destinationPath, this.options, callback);
160151
});
161-
162152
// To generate Signature for upload request
163-
this.getAuthenticationParameters = function(token, timestamp) {
164-
return signature.getAuthenticationParameters(token, timestamp, this.options);
153+
this.getAuthenticationParameters = function (token, expire) {
154+
return signature.getAuthenticationParameters(token, expire, this.options);
165155
};
166-
167156
// Get bulk job status API
168-
this.getBulkJobStatus = promisify(function(jobId, callback) {
157+
this.getBulkJobStatus = promisify(function (jobId, callback) {
169158
return manage.getBulkJobStatus(jobId, this.options, callback);
170159
});
171-
172160
// To calculate distance between two pHash strings
173-
this.pHashDistance = function(firstPHash, secondPHash) {
161+
this.pHashDistance = function (firstPHash, secondPHash) {
174162
return pHashUtils.pHashDistance(firstPHash, secondPHash);
175-
}
163+
};
176164
};
177-
178-
module.exports = ImageKit;
165+
module.exports = ImageKit;
166+
export {};

0 commit comments

Comments
 (0)