npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adaptive-card-transformer

v1.0.10

Published

APIs to transform other Cards to equivalent Adaptive Cards

Downloads

4

Readme

AdaptiveCard Transformer Library

This package contains the APIs to transform non-Adaptive Cards to Adaptive Cards. Presently it supports below cards:

  1. Hero Card
  2. Thumbnail Card
  3. O365 Connector Card

Installation

To install the stable version:

npm

npm install adaptive-card-transformer --save-dev

yarn

yarn add adaptive-card-transformer --dev

Unit Tests

yarn test

Usage

Transform card

Below is an example on how to transform a Hero card to Adaptive card.

import * as adaptiveCardTransformer from "adaptive-card-transformer";

// Define a HeroCard object
let heroCard: adaptiveCardTransformer.Hero.HeroCard = {
    title: "Hero title",
    subtitle: "Hero subtitle",
    text: "Hero text",
    images: [{
        "url": "https://hero.com/image.jpg"
    }],
    buttons: [{
        "type": "openUrl",
        "title": "View website",
        "value": "https://hero.com/website"
    }]
};

// Wrap it within a CardAttachment object
let heroCardAttachment: adaptiveCardTransformer.CardAttachment = {
    contentType: adaptiveCardTransformer.CardContentType.HeroCard,
    content: heroCard
};

// Transform the CardAttachment object
let transformedCardAttachment = adaptiveCardTransformer.transformCardAttachment(heroCardAttachment);

// Extract the transformed AdaptiveCard object
let adaptiveCard: adaptiveCardTransformer.Adaptive.AdaptiveCard = transformedCardAttachment.content;

Utilities

Additionally this package also provides few utilities like below.

import * as adaptiveCardTransformer from "adaptive-card-transformer";

// To recursively extract any type of elements from an Adaptive card json
let allImages = adaptiveCardTransformer.filterCardElements(adaptiveCardJson.body, "Image");
let first5TextBlocks = adaptiveCardTransformer.filterCardElements(adaptiveCardJson.body, "TextBlock", 5);
let allOpenUrlActions = adaptiveCardTransformer.filterCardElements(adaptiveCardJson.actions, "Action.OpenUrl");

// To derive the fallback text from an Adaptive card json
// This will return the adaptiveCard.fallbackText, if any, or
// the first TextBlock content, if any
let fallbackText = adaptiveCardTransformer.getCardFallbackText(adaptiveCardJson);

// To derive the fallback url from an Adaptive card json
// This will return the first Action.OpenUrl target giving preference to below order:
// 1. adaptiveCard.selectAction
// 2. adaptiveCard.actions
// 3. actionSet.actions within adaptiveCard.body
let fallbackUrl = adaptiveCardTransformer.getCardFallbackUrl(adaptiveCardJson);