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

linear-gradient-parser

v1.1.8

Published

Parses a SVG linear gradient string / parsed JSON into css background image property

Downloads

5,791

Readme

linear-gradient-parser

Converts a linear gradient SVG String / Json rep into CSS background property

Installation

npm i linear-gradient-parser

Live Demo

Usage

Linear gradient parser comes in handy when you need get a svg linear gradient as background. It can accepts both SVG linearGradient string / Json as input in order to produce it's background.

import parser from 'linear-gradient-parser';

// SVG String input
const linearGradientString = `
<linearGradient xmlns="http://www.w3.org/2000/svg" gradientUnits="userSpaceOnUse" x1="17.5001" y1="32" x2="17.5001" y2="2.9711">
    <stop offset="0" style="stop-color:#FCB3A4"/>
    <stop offset="1" style="stop-color:#DA5899"/>
</linearGradient>
`

const stringResult = parser.getBackground(linearGradientString);

console.log(stringResult) 
//outputs : {background: "linear-gradient(0deg, rgb(252, 179, 164) 0%, rgb(218, 88, 153) 100%)", angle: 0}

// JSON input
const linearGradient = {
    x1: '17.5001',
    y1: '32',
    x2: '17.5001',
    y2: '2.9711',
    stops: [
        { color: '#FCC3A4', offset: '0', opacity: 0.5 },
        { color: '#AAA899', offset: '1' }
    ]
};

const jsonResult = parser.getBackground(linearGradient);

console.log(jsonResult) 
//outputs : {background: "linear-gradient(0deg, rgb(252, 179, 164) 0%, rgb(218, 88, 153) 100%)", angle: 0}

// Using angle generator
const gradientCords = parser.getGradientCords(90);

//outputs : { x1: 0, x2: 1, y1: 0, y2: 0 }

Methods

getBackground

Converts a linear gradient into a background representation.

| Name | Type | Default Value | Required? | Description |-|-|-|-|- | linearGradient | String|LinearGradient | undefined | Yes | The linear gradient to parse

Returns: { angle: Number , background: String }

getGradientCords

Builds a linear gradient position attributes for a given angle.

| Name | Type | Default Value | Required? | Description |-|-|-|-|- | angle | Number | 0 | Yes | The angle to create the x1 / x2 / y1 / y2 cords from.

Returns: { x1: Number, x2: Number, y1: Number, y2: Number }