furtrack-api 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +67 -2
- package/src/index.test.js +1 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -119,7 +119,7 @@ class FurtrackAPI {
|
|
|
119
119
|
'2:': this.TagTypes.Maker,
|
|
120
120
|
'3:': this.TagTypes.Photographer,
|
|
121
121
|
'5:': this.TagTypes.Event,
|
|
122
|
-
'6': this.TagTypes.Species,
|
|
122
|
+
'6:': this.TagTypes.Species,
|
|
123
123
|
|
|
124
124
|
};
|
|
125
125
|
|
|
@@ -202,13 +202,78 @@ class FurtrackAPI {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
static getTagsByType(tags, type) {
|
|
206
206
|
return tags
|
|
207
207
|
.map(tag => this.parseTag(tag.tagName))
|
|
208
208
|
.filter(parsed => parsed.type === type)
|
|
209
209
|
.map(parsed => parsed.value);
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Fetches all character tags associated with a maker tag.
|
|
214
|
+
* Returns the full character metadata including tag counts and followers.
|
|
215
|
+
*
|
|
216
|
+
* @param {string} makerTag - The maker tag (e.g., "wild_dog_works" or "maker:wild_dog_works").
|
|
217
|
+
* @returns {Promise<Array>} Array of character tag objects with metadata.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* const characters = await api.getCharactersByMaker('wild_dog_works');
|
|
221
|
+
* // Returns: [{ tagName: '1:colby_(husky)', tagType: 1, tagTitle: 'Colby', ... }, ...]
|
|
222
|
+
*/
|
|
223
|
+
async getCharactersByMaker(makerTag) {
|
|
224
|
+
// Normalize tag format
|
|
225
|
+
if (!makerTag.startsWith('2:')) {
|
|
226
|
+
makerTag = `2:${makerTag}`;
|
|
227
|
+
}
|
|
228
|
+
const tagData = await this.getTag(makerTag.replace('2:', 'maker:'));
|
|
229
|
+
return tagData.tagmeta?.tagChildrenFull || [];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Fetches all related tags for a character, including makers, species, and color tags.
|
|
234
|
+
*
|
|
235
|
+
* @param {string} characterTag - The character tag (e.g., "colby_(husky)" or "character:colby_(husky)").
|
|
236
|
+
* @returns {Promise<Object>} Object with categorized related tags.
|
|
237
|
+
* @returns {Promise<Object>.makers} Array of maker tag values.
|
|
238
|
+
* @returns {Promise<Object>.species} Array of species tag values.
|
|
239
|
+
* @returns {Promise<Object>.colors} Array of color/general tag values.
|
|
240
|
+
* @returns {Promise<Object>.all} Array of all related tag names.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* const related = await api.getRelatedTagsByCharacter('colby_(husky)');
|
|
244
|
+
* // Returns: { makers: ['wild_dog_works', 'pyrope_costumes'], species: ['husky'], colors: ['black', 'blue', ...], all: [...] }
|
|
245
|
+
*/
|
|
246
|
+
async getRelatedTagsByCharacter(characterTag) {
|
|
247
|
+
// Normalize tag format
|
|
248
|
+
if (!characterTag.startsWith('1:')) {
|
|
249
|
+
characterTag = `1:${characterTag}`;
|
|
250
|
+
}
|
|
251
|
+
const tagData = await this.getTag(characterTag.replace('1:', 'character:'));
|
|
252
|
+
const tagAlso = tagData.tagmeta?.tagAlso || [];
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
makers: FurtrackAPI.getTagsByType(tagAlso.map(t => ({ tagName: t })), FurtrackAPI.TagTypes.Maker),
|
|
256
|
+
species: FurtrackAPI.getTagsByType(tagAlso.map(t => ({ tagName: t })), FurtrackAPI.TagTypes.Species),
|
|
257
|
+
colors: tagAlso.filter(t => !t.startsWith('1:') && !t.startsWith('2:') && !t.startsWith('3:') && !t.startsWith('5:') && !t.startsWith('6:')),
|
|
258
|
+
all: tagAlso
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Fetches all makers associated with a character tag.
|
|
264
|
+
*
|
|
265
|
+
* @param {string} characterTag - The character tag (e.g., "colby_(husky)" or "character:colby_(husky)").
|
|
266
|
+
* @returns {Promise<Array>} Array of maker tag values.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* const makers = await api.getMakersByCharacter('colby_(husky)');
|
|
270
|
+
* // Returns: ['wild_dog_works', 'pyrope_costumes']
|
|
271
|
+
*/
|
|
272
|
+
async getMakersByCharacter(characterTag) {
|
|
273
|
+
const related = await this.getRelatedTagsByCharacter(characterTag);
|
|
274
|
+
return related.makers;
|
|
275
|
+
}
|
|
276
|
+
|
|
212
277
|
}
|
|
213
278
|
|
|
214
279
|
module.exports = FurtrackAPI;
|
package/src/index.test.js
CHANGED
|
@@ -50,7 +50,7 @@ describe('FurtrackAPI', () => {
|
|
|
50
50
|
expect(result).toEqual({ type: FurtrackAPI.TagTypes.Event, value: 'SomeEvent' });
|
|
51
51
|
});
|
|
52
52
|
test('parses species tag', () => {
|
|
53
|
-
const result = api.parseTag('
|
|
53
|
+
const result = api.parseTag('6:Wolf');
|
|
54
54
|
expect(result).toEqual({ type: FurtrackAPI.TagTypes.Species, value: 'Wolf' });
|
|
55
55
|
});
|
|
56
56
|
test('parses general tag', () => {
|