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 🙏

© 2026 – Pkg Stats / Ryan Hefner

derivaintegra

v1.0.0

Published

Uma biblioteca JavaScript para calcular derivadas e integrais com passo-a-passo.

Downloads

22

Readme

Derivaintegra (ES Module)

derivaintegra é uma biblioteca JavaScript pura para derivação simbólica e integração de equações matemáticas, otimizada como ES Module (ESM) moderno.

Ela recebe uma expressão como string (ex: "x^2 * sin(x)") e retorna a string do resultado, juntamente com um construtor de passos (StepsBuilder) que gera um HTML da resolução passo a passo.

Este projeto foi construído como um parser descendente recursivo e não possui dependências externas.

Instalação / Configuração

Uso Local (Sem NPM)

Basta baixar o arquivo derivaintegra.js e colocá-lo no seu projeto.

Uso via NPM

npm install derivaintegra

Nota: Certifique-se de que seu projeto está configurado como module (adicione "type": "module" no seu package.json ou use a extensão .mjs).

Como Usar

1. Importando em Arquivos JavaScript (Local)

// Importe diretamente do arquivo
import { derivar, integrar, StepsBuilder } from './derivaintegra.js';

// --- Exemplo de Derivação ---
const expressaoD = "cos(x^2)";
// Notações suportadas: 'lagrange' (f') ou 'leibniz' (d/dx)
const resultadoD = derivar(expressaoD, 'leibniz');

// A string da derivada final
console.log(resultadoD.derivadaStr);
// Saída: "-\sin(x^2) * (2x)"

// Renderizar passos (HTML)
console.log(resultadoD.stepsBuilder.render());

2. Diretamente no Navegador

Para usar no navegador sem bundlers (Webpack/Vite), utilize a tag type="module".

<!DOCTYPE html>
<html>
<head>
    <title>Teste Derivaintegra</title>
    <!-- Opcional: KaTeX para renderizar a matemática visualmente -->
    <link rel="stylesheet" href="[https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css](https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css)">
    <script defer src="[https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js](https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js)"></script>
</head>
<body>
    <h3>Resultado:</h3>
    <div id="output"></div>

    <!-- Importante: type="module" -->
    <script type="module">
        // Importação local ou via CDN (ex: esm.sh ou jsdelivr)
        import { integrar } from './derivaintegra.js';

        const { integralStr, stepsBuilder } = integrar("x^2 * exp(x)");
        
        // Exibe o resultado
        console.log("Integral:", integralStr);
        
        // Renderiza os passos no HTML
        document.getElementById('output').innerHTML = stepsBuilder.render();
    </script>
</body>
</html>

Regras e Funcionalidades Suportadas

Derivação (derivar)

O motor de derivação suporta a Regra da Cadeia completa para funções aninhadas.

  • Regras Básicas: Constante ($c \to 0$), Variável ($x \to 1$), Potência ($ax^n$).

  • Aritmética: Regras da Soma, Subtração, Produto e Quociente.

  • Trigonometria: $\sin(u)$, $\cos(u)$, $\tan(u)$.

  • Transcendentais: $\ln(u)$, $e^u$ (exp(u)), $\sqrt{u}$.

Integração (integrar)

O motor de integração aplica heurísticas para identificar o método de resolução mais adequado:

  1. Integrais Imediatas:

    • Potência: $\int x^n dx$

    • Logarítmica: $\int \frac{1}{x} dx$

    • Exponencial: $\int e^x dx$

    • Trigonométrica: $\int \sin(x) dx$, $\int \cos(x) dx$

  2. Regra da Substituição ($u$-sub):

    • Identifica automaticamente padrões da forma $\int f(g(x)) \cdot g'(x) dx$.

    • Ex: $\int \cos(x^2) \cdot 2x dx$

  3. Integração por Partes (Recursiva):

    • Resolve produtos de polinômios por funções transcendentais usando a regra LIATE.

    • Ex: $\int x^2 \cdot \sin(x) dx$, $\int x \cdot e^x dx$.

API (Funções Exportadas)

derivar(expr: string, notation: string)

Calcula a derivada da expressão.

  • expr: A expressão a ser derivada (ex: "x^2 + sin(x)").

  • notation: 'leibniz' (para d/dx) ou 'lagrange' (para f'(x)).

  • Retorna: { derivadaStr: string, stepsBuilder: StepsBuilder }

integrar(expr: string)

Calcula a integral (indefinida) da expressão.

  • expr: A expressão a ser integrada (ex: "x * cos(x)").

  • Retorna: { integralStr: string, stepsBuilder: StepsBuilder }

    • Nota: integralStr é a antiderivada simplificada.

StepsBuilder

Classe utilitária que armazena a árvore de resolução.

  • Método .render(): Retorna uma string HTML (<div class="step">...</div>) pronta para ser inserida na página.

VERSION

Constante contendo a versão atual da biblioteca (ex: "2.1.0").

Licença

MIT