ramda#prop TypeScript Examples

The following examples show how to use ramda#prop. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: webhook.service.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
public async executeWebhook(type: string, data: any): Promise<void> {
		const tenant = await this.tenantService.findOne()

		const hooks = await this.webhookRepository.createQueryBuilder('Webhook')
			.andWhere('Webhook.type = :type', { type })
			.getMany();

		hooks.forEach((hook) => {
			if (hook.destination === "discord") {
				if (!prop(hook.type)(discordTransform)) {
					return;
				}

				got.post(hook.url, {
					json: {
						embeds: [{
							...prop(hook.type)(discordTransform)(data),
							author: {
								name: tenant.name,
								icon_url: tenant?.settings?.logo
							},
							color: parseInt(tenant?.settings?.primaryColor.replace('#', ''), 16),
						}]
					}
				}).catch(() => {
					// Swallow
				})
				return;
			}

			got.post(hook.url, {
				json: {
					type,
					data
				},
			})
		});

	}
Example #2
Source File: tenant-input.component.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
public writeValue(value: any) {
		if (!value) {
			return;
		}

		this.dynamicInputService.fetchTenants()
			.pipe(first())
			.subscribe(data => {
				if (!this.multiple) {
					return setTimeout(() => this.control.setValue({
						value,
						label: prop('name')(data.find((contentItem) => contentItem.uuid === value))
					}));
				}

				const mappedValue = value.map((item) => ({
					value: item,
					label: prop('name')(data.find((contentItem) => contentItem.uuid === item))
				}));
				this.control.setValue(mappedValue);
			});
	}
Example #3
Source File: role-input.component.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
public writeValue(value: any) {
		if (!value) {
			return;
		}

		this.dynamicInputService.fetchRoles()
			.pipe(first())
			.subscribe(data => {
				if (!this.multiple) {
					return setTimeout(() => this.control.setValue({
						value,
						label: prop('name')(data.find((contentItem) => contentItem.uuid === value))
					}));
				}

				const mappedValue = value.map((item) => ({
					value: item,
					label: prop('name')(data.find((contentItem) => contentItem.uuid === item))
				}));
				this.control.setValue(mappedValue);
			});
	}
Example #4
Source File: category-input.component.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
public writeValue(value: any) {
		if (!value) {
			return;
		}

		this.dynamicInputService.fetchCategories()
			.pipe(first())
			.subscribe(data => {
				if (!this.multiple) {
					return setTimeout(() => this.control.setValue({
						value,
						label: prop('name')(data.find((contentItem) => contentItem.uuid === value))
					}));
				}

				const mappedValue = value.map((item) => ({
					value: item,
					label: prop('name')(data.find((contentItem) => contentItem.uuid === item))
				}));
				this.control.setValue(mappedValue);
			});
	}
Example #5
Source File: timetable.page.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
public ngOnInit(): void {
		this.fetchData();

		this.socketService.socket.on('timetable-updated', () => {
			this.fetchData();
		});

		// TODO: add takeUntill
		this.sessionQuery.user$.subscribe((user) => this.user = user);
		this.sessionQuery.permissions$.subscribe((permissions) => this.permissions = permissions);

		this.slotTypeService
			.fetch()
			.pipe(first())
			.subscribe();

		this.slotQuery.selectAll()
			.pipe(
				map(slots => {
					return slots.map((slot) => ({
						...slot,
						id: (slot as any).uuid,
						start: moment.unix(Number(slot.start)).toDate(),
						end: moment.unix(Number(slot.end) - 1).toDate(),
						color: {
							primary: pathOr('#000', ['slotType', 'color'])(slot),
							secondary: pathOr('#000', ['slotType', 'color'])(slot)
						},
						meta: {
							...(slot as any).user,
							originalTimings: {
								start: moment.unix(Number(slot.start)).toDate(),
								end: moment.unix(Number(slot.end)).toDate(),
							},
							editable: this.permissions.includes('timetable/update-other')
								|| path(['user', 'uuid'])(slot) === prop('uuid')(this.user)
						}
					}));
				})
			).subscribe((slots) => {
				this.slots = slots;
				this.refresh();
			});
	}
Example #6
Source File: routes.ts    From the-fake-backend with ISC License 5 votes vote down vote up
export function getRoutesPaths(routes: Route[]) {
  return routes.map(prop('path'));
}
Example #7
Source File: proxy.ts    From the-fake-backend with ISC License 5 votes vote down vote up
/**
   * Get all proxy names.
   */
  private getProxyNames() {
    return this.proxies.map(prop('name'));
  }
Example #8
Source File: prompts.ts    From the-fake-backend with ISC License 5 votes vote down vote up
filterByPredicate = (list: string[]) => (predicate: string = '') =>
  fuzzy.filter(predicate, list).map(prop('original'))
Example #9
Source File: overrides.ts    From the-fake-backend with ISC License 5 votes vote down vote up
function getOverridableRoutesMethodsTypesNames(route: Route) {
  return filterOverridableMethods(route.methods).map(
    pipe(prop('type'), formatMethodType)
  );
}
Example #10
Source File: overrides.ts    From the-fake-backend with ISC License 5 votes vote down vote up
function getOverridesNames(overrides: MethodOverride[]) {
  return overrides.map(prop('name'));
}
Example #11
Source File: html-summary.ts    From the-fake-backend with ISC License 5 votes vote down vote up
sortByPath = sortBy(compose(toLower, prop('path')))
Example #12
Source File: L5-substitution-adt.ts    From interpreters with MIT License 5 votes vote down vote up
extendSub = (sub: Sub, v: TVar, te: TExp): Result<Sub> =>
    bind(makeSub([v], [te]), (sub2: Sub) => {
        const updatedTEs = map((te) => applySub(sub2, te), sub.tes);
        return includes(v.var, map(prop('var'), sub.vars)) ? makeSub(sub.vars, updatedTEs) :
               makeSub(cons(v, sub.vars), cons(te, updatedTEs));
    })
Example #13
Source File: songFetcher.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
fetchSongData = async (streamUrl: string, streamType: string) => {
	const userAgent = new UserAgent();
	if(streamType == "icecast"){
		const radioServerResponse = await got.get(streamUrl ,{
			resolveBodyOnly: true,
			responseType: 'json',
			timeout: 5000,
			headers: {
				'User-Agent': userAgent.toString()
			}
		}).catch((e) => {});

		if (Array.isArray(path(['icestats', 'source'])(radioServerResponse))) {
			const source = mergeAll<any>(path<object[]>(['icestats', 'source'])(radioServerResponse));
			return (prop('title')(source) as string);
		} else {
			return pathOr('', ['icestats', 'source', 'title'])(radioServerResponse);
		}
	};

	if(streamType == "shoutcast"){
		const radioServerResponse = await got.get(streamUrl ,{
			resolveBodyOnly: true,
			responseType: 'json',
			timeout: 5000,
			headers: {
				'User-Agent': userAgent.toString()
			}
		}).catch(() => {});

		return pathOr('', ['songtitle'])(radioServerResponse);
	};

	if(streamType == "zeno"){
		const radioServerResponse = await got.get(streamUrl, {
			resolveBodyOnly: true,
			responseType: 'json',
			timeout: 5000,
			headers: {
				'User-Agent': userAgent.toString()
			}
		}).catch(() => {});

		return pathOr('', ['artist'])(radioServerResponse) + ' - ' + pathOr('', ['title'])(radioServerResponse);
	};
}
Example #14
Source File: serviceResponseMapper.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
manualSearchMapper = (service: "deezer" | "spotify", response: any): Partial<Song>[] => {
	if (service === "spotify") {
		const tracks = pathOr<any[]>(null, ['tracks', 'items'])(response);

		return tracks.map(track => ({
			title: prop('name')(track),
			artist: path<string>(['artists', 0, 'name'])(track),
			album: pathOr('Unknown Album', ['album', 'name'])(track),
			graphic: {
				large: pathOr(null, ['album', 'images', 0, 'url'])(track),
				medium: pathOr(null, ['album', 'images', 1, 'url'])(track),
				small: pathOr(null, ['album', 'images', 2, 'url'])(track),
			},
			extraInfo: {
				album: pick(['album_type', 'external_urls', 'href', 'id', 'release_date', 'release_date_precision', 'total_tracks', 'uri'])(propOr({}, 'album')(track)),
				artist: pick(['id', 'name', 'uri', 'href'])(pathOr({}, ['artists', 0])(track)),
				track: pick(['href', 'external_urls', 'uri', 'explicit', 'id'])(track)
			},
			previewUrl: pathOr(null, ['preview_url'])(track),
			releaseDate: pathOr(new Date(), ['album', 'release_date'])(track),
			durationMs: pathOr(1000, ['duration_ms'])(track),
		}));
	}

	if (service === "deezer") {
		const tracks = pathOr<any[]>(null, ['data'])(response);

		return tracks.map(track => ({
			title: prop('title')(track),
			artist: path<string>(['artist', 'name'])(track),
			album: pathOr('Unknown Album', ['album', 'title'])(track),
			graphic: {
				large: pathOr(null, ['album', 'cover_xl'])(track),
				medium: pathOr(null, ['album', 'cover_big'])(track),
				small: pathOr(null, ['album', 'cover_medium'])(track),
			},
			previewUrl: pathOr(null, ['preview'])(track),
			releaseDate: new Date(),
			durationMs: pathOr(1000, ['duration'])(track),
		}));
	}

	if (service === "apple-music") {
		const tracks = pathOr<any[]>(null, ['results'])(response);

		return tracks.map(track => ({
			title: prop('trackName')(track),
			artist: path<string>(['artistName'])(track),
			album: pathOr('Unknown Album', ['collectionName'])(track),
			graphic: {
				large: pathOr(null, ['artworkUrl100'])(track)?.replace('100x100bb', '640x640bb'),
				medium: pathOr(null, ['artworkUrl60'])(track)?.replace('60x60bb', '300x300bb'),
				small: pathOr(null, ['artworkUrl30'])(track)?.replace('30x30bb', '64x64bb'),
			},
			extraInfo: {
				albumUrl: pathOr(null, ['collectionViewUrl'])(track),
				trackUrl: pathOr(null, ['trackViewUrl'])(track),
				artistUrl: pathOr(null, ['artistViewUrl'])(track),
				primaryGenreName: pathOr(null, ['primaryGenreName'])(track),
				albumPrice: pathOr(null, ['collectionPrice'])(track),
				trackPrice: pathOr(null, ['trackPrice'])(track),
				currency: pathOr(null, ['currency'])(track),
				country: pathOr(null, ['country'])(track),
			},
			previewUrl: pathOr(null, ['previewUrl'])(track),
			releaseDate: pathOr(null, ['releaseDate'])(track),
			durationMs: pathOr(1000, ['trackTimeMillis'])(track),
		}));
	}
}
Example #15
Source File: user.service.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
public async getRole(userUuid: string): Promise<any> {
		const roleRelation = await this.userRoleRepository.findOne({
			userUuid,
		});

		return prop('role')(roleRelation);
	}
Example #16
Source File: RefactoredFlickr.tsx    From react-js-tutorial with MIT License 5 votes vote down vote up
images = compose<
  FlickrResponse,
  FlickrResponseItem[],
  JQuery<HTMLElement>[]
>(map(mediaToImg), prop("items"))
Example #17
Source File: RefactoredFlickr.tsx    From react-js-tutorial with MIT License 5 votes vote down vote up
mediaUrl = compose<FlickrResponseItem, FlickrMediaURL, string>(
  prop("m"),
  prop("media")
)
Example #18
Source File: Flickr.tsx    From react-js-tutorial with MIT License 5 votes vote down vote up
mediaUrls = compose<FlickrResponse, FlickrResponseItem[], string[]>(
  map(mediaUrl),
  prop("items")
)
Example #19
Source File: Flickr.tsx    From react-js-tutorial with MIT License 5 votes vote down vote up
mediaUrl = compose<FlickrResponseItem, FlickrMediaURL, string>(
  prop("m"),
  prop("media")
)