Skip to content

Commit eff7dec

Browse files
committed
docs(bundle): regenerate every size figure from the tree-shaking script
The figures were measured before the datasets were packed. They now come from node scripts/tree-shaking.ts on the built branch: the size table of the getting started page, the isValidCpf intro figure, the getCities, isValidCid10 and getCid10 sizes of the utilities reference, the state and city guides and their snippets. getStates is 2.2 KB, not 2.5 KB.
1 parent bba559b commit eff7dec

13 files changed

Lines changed: 51 additions & 51 deletions

File tree

‎docs/getting-started.md‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,25 @@ A few utils embed an official dataset and weigh far more than everything else co
6868

6969
| Util | Dataset | Minified | Gzipped |
7070
| --- | --- | --- | --- |
71-
| `getCid10` | CID-10 V2008 categories and subcategories plus the SIM `U07` codes, with the DATASUS descriptions | 988.3 KB | 123.6 KB |
72-
| `getMunicipalitiesByAreaCode` · `getAreaCodeByMunicipalityCode` | 5571 IBGE municipalities, with the DDD of each (Anatel) | 165.0 - 167.8 KB | 52.1 - 52.8 KB |
73-
| `getMunicipalities` · `getMunicipalityByCode` · `getCodeByMunicipalityName` · `getMunicipality` | 5571 IBGE municipalities, with names and codes | 153.6 - 154.2 KB | 49.4 - 49.8 KB |
74-
| `getCities` | 5571 IBGE municipality names | 153.4 KB | 49.2 KB |
75-
| `getCest` | CEST descriptions and segments (Convênio ICMS 142/18) | 111.5 KB | 24.0 KB |
76-
| `getCbo` | CBO 2002 occupation titles | 107.6 KB | 24.7 KB |
77-
| `getCnae` | CNAE-Subclasses 2.3 | 86.6 KB | 17.9 KB |
78-
| `getNbs` | NBS 2.0 (Nomenclatura Brasileira de Serviços) descriptions | 75.5 KB | 11.5 KB |
79-
| `getCfop` | CFOP operation descriptions | 66.7 KB | 5.2 KB |
71+
| `getCid10` | CID-10 V2008 categories and subcategories plus the SIM `U07` codes, with the DATASUS descriptions | 721.5 KB | 113.5 KB |
72+
| `getCest` | CEST descriptions and segments (Convênio ICMS 142/18) | 102.2 KB | 24.0 KB |
73+
| `getMunicipalitiesByAreaCode` · `getAreaCodeByMunicipalityCode` | 5571 IBGE municipalities, with the DDD of each (Anatel) | 23.5 - 90.2 KB | 5.6 - 32.9 KB |
74+
| `getCbo` | CBO 2002 occupation titles | 80.6 KB | 24.1 KB |
75+
| `getMunicipalities` · `getMunicipalityByCode` · `getCodeByMunicipalityName` · `getMunicipality` | 5571 IBGE municipalities, with names and codes | 76.0 - 76.9 KB | 29.4 - 29.9 KB |
76+
| `getCnae` | CNAE-Subclasses 2.3 | 66.8 KB | 17.7 KB |
77+
| `getCities` | 5571 IBGE municipality names | 64.2 KB | 26.4 KB |
78+
| `getCfop` | CFOP operation descriptions | 56.9 KB | 5.1 KB |
79+
| `getNbs` | NBS 2.0 (Nomenclatura Brasileira de Serviços) descriptions | 51.1 KB | 11.3 KB |
8080
| `getClassTrib` | cClassTrib (IBS/CBS) names and descriptions | 50.0 KB | 9.0 KB |
81-
| `getBanks` · `getBankByCode` · `getBankByIspb` | Banco Central STR participants (COMPE + ISPB) | 37.6 - 37.8 KB | 9.0 - 9.2 KB |
82-
| `isValidNcm` | NCM (Nomenclatura Comum do Mercosul) codes | 29.6 KB | 8.9 KB |
83-
| `getIsbnInfo` · `formatIsbn` | ISBN ranges of the International ISBN Agency (RangeMessage) | 27.0 - 27.1 KB | 6.2 KB |
84-
| `isValidCid10` | CID-10 V2008 category and subcategory codes plus the SIM `U07` codes, without the descriptions | 26.2 KB | 6.8 KB |
85-
| `getServiceItem` | Service list of the Lei Complementar 116/2003 | 26.0 KB | 8.0 KB |
86-
| `isValidCbo` | CBO 2002 occupation codes, without the titles | 6.6 KB | 1.7 KB |
87-
| `isValidCnae` | CNAE-Subclasses 2.3 codes, without the descriptions | 4.5 KB | 1.9 KB |
88-
| `isValidCest` | CEST codes, without the descriptions | 3.5 KB | 0.8 KB |
89-
| `isValidNbs` | NBS 2.0 codes, without the descriptions | 3.4 KB | 1.2 KB |
81+
| `isValidNcm` | NCM (Nomenclatura Comum do Mercosul) codes | 29.6 KB | 9.0 KB |
82+
| `getBanks` · `getBankByCode` · `getBankByIspb` | Banco Central STR participants (COMPE + ISPB) | 26.2 - 26.5 KB | 7.6 - 7.8 KB |
83+
| `getServiceItem` | Service list of the Lei Complementar 116/2003 | 25.5 KB | 8.2 KB |
84+
| `getIsbnInfo` · `formatIsbn` | ISBN ranges of the International ISBN Agency (RangeMessage) | 15.1 - 15.3 KB | 5.4 - 5.5 KB |
85+
| `isValidCbo` | CBO 2002 occupation codes, without the titles | 6.7 KB | 1.7 KB |
86+
| `isValidCid10` | CID-10 V2008 category and subcategory codes plus the SIM `U07` codes, without the descriptions | 6.7 KB | 2.4 KB |
87+
| `isValidCnae` | CNAE-Subclasses 2.3 codes, without the descriptions | 4.6 KB | 1.9 KB |
88+
| `isValidCest` | CEST codes, without the descriptions | 3.6 KB | 0.8 KB |
89+
| `isValidNbs` | NBS 2.0 codes, without the descriptions | 3.5 KB | 1.3 KB |
9090

9191
The root of the package is a single ESM module, so a bundler cannot split one of these datasets out of it: importing a heavy util from the root puts its whole dataset in your main bundle, and a dynamic `import()` of the root does not help. To lazy-load one, import it from its own subpath:
9292

‎docs/guides/state-city.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords: ["state and city select", "IBGE municipalities", "getMunicipalities",
66

77
Pick a state and its cities fill the second select. Pick the framework: each example runs the code below it, which you can copy as is.
88

9-
The point of this one is when each table is loaded, and the answer is: when someone opens the select that shows it. Not with the page, and not when a state is picked either. A form where the city is filled in by something else, or left alone, never fetches 148 KB of municipalities. The states are 27 rows, 2.5 KB; the municipalities are 5,571 of them, 148 KB. Each util is its own subpath, so `await import("@brazilian-utils/brazilian-utils/get-municipalities")` fetches that table and nothing else. Each option takes the IBGE `code` of the municipality as its value and the `name` as its label, since names repeat across states (there are two "Pau D'Arco"). A bundler makes it a chunk of its own; the browser fetches it once and keeps it, so only the first opening waits.
9+
The point of this one is when each table is loaded, and the answer is: when someone opens the select that shows it. Not with the page, and not when a state is picked either. A form where the city is filled in by something else, or left alone, never fetches 76 KB of municipalities. The states are 27 rows, 2.2 KB; the municipalities are 5,571 of them, 76 KB. Each util is its own subpath, so `await import("@brazilian-utils/brazilian-utils/get-municipalities")` fetches that table and nothing else. Each option takes the IBGE `code` of the municipality as its value and the `name` as its label, since names repeat across states (there are two "Pau D'Arco"). A bundler makes it a chunk of its own; the browser fetches it once and keeps it, so only the first opening waits.
1010

1111

1212
<div class="example" data-name="React" data-demo="/snippets/live/?dir=state-city/react&example=state-city.tsx">

‎docs/pt-br/getting-started.md‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,25 @@ Alguns utilitários embutem uma base de dados oficial e pesam muito mais que tod
6868

6969
| Utilitário | Base de dados | Minificado | Gzip |
7070
| --- | --- | --- | --- |
71-
| `getCid10` | categorias e subcategorias da CID-10 V2008 mais os códigos `U07` do SIM, com as descrições do DATASUS | 988,3 KB | 123,6 KB |
72-
| `getMunicipalitiesByAreaCode` · `getAreaCodeByMunicipalityCode` | 5571 municípios do IBGE, com o DDD de cada um (Anatel) | 165,0 - 167,8 KB | 52,1 - 52,8 KB |
73-
| `getMunicipalities` · `getMunicipalityByCode` · `getCodeByMunicipalityName` · `getMunicipality` | 5571 municípios do IBGE, com nomes e códigos | 153,6 - 154,2 KB | 49,4 - 49,8 KB |
74-
| `getCities` | nomes dos 5571 municípios do IBGE | 153,4 KB | 49,2 KB |
75-
| `getCest` | descrições e segmentos do CEST (Convênio ICMS 142/18) | 111,5 KB | 24,0 KB |
76-
| `getCbo` | títulos das ocupações da CBO 2002 | 107,6 KB | 24,7 KB |
77-
| `getCnae` | CNAE-Subclasses 2.3 | 86,6 KB | 17,9 KB |
78-
| `getNbs` | descrições da NBS 2.0 (Nomenclatura Brasileira de Serviços) | 75,5 KB | 11,5 KB |
79-
| `getCfop` | descrições das operações do CFOP | 66,7 KB | 5,2 KB |
71+
| `getCid10` | categorias e subcategorias da CID-10 V2008 mais os códigos `U07` do SIM, com as descrições do DATASUS | 721,5 KB | 113,5 KB |
72+
| `getCest` | descrições e segmentos do CEST (Convênio ICMS 142/18) | 102,2 KB | 24,0 KB |
73+
| `getMunicipalitiesByAreaCode` · `getAreaCodeByMunicipalityCode` | 5571 municípios do IBGE, com o DDD de cada um (Anatel) | 23,5 - 90,2 KB | 5,6 - 32,9 KB |
74+
| `getCbo` | títulos das ocupações da CBO 2002 | 80,6 KB | 24,1 KB |
75+
| `getMunicipalities` · `getMunicipalityByCode` · `getCodeByMunicipalityName` · `getMunicipality` | 5571 municípios do IBGE, com nomes e códigos | 76,0 - 76,9 KB | 29,4 - 29,9 KB |
76+
| `getCnae` | CNAE-Subclasses 2.3 | 66,8 KB | 17,7 KB |
77+
| `getCities` | nomes dos 5571 municípios do IBGE | 64,2 KB | 26,4 KB |
78+
| `getCfop` | descrições das operações do CFOP | 56,9 KB | 5,1 KB |
79+
| `getNbs` | descrições da NBS 2.0 (Nomenclatura Brasileira de Serviços) | 51,1 KB | 11,3 KB |
8080
| `getClassTrib` | nomes e descrições do cClassTrib (IBS/CBS) | 50,0 KB | 9,0 KB |
81-
| `getBanks` · `getBankByCode` · `getBankByIspb` | participantes do STR do Banco Central (COMPE + ISPB) | 37,6 - 37,8 KB | 9,0 - 9,2 KB |
82-
| `isValidNcm` | códigos NCM (Nomenclatura Comum do Mercosul) | 29,6 KB | 8,9 KB |
83-
| `getIsbnInfo` · `formatIsbn` | faixas do ISBN da Agência Internacional do ISBN (RangeMessage) | 27,0 - 27,1 KB | 6,2 KB |
84-
| `isValidCid10` | códigos das categorias e subcategorias da CID-10 V2008 mais os códigos `U07` do SIM, sem as descrições | 26,2 KB | 6,8 KB |
85-
| `getServiceItem` | lista de serviços da Lei Complementar 116/2003 | 26,0 KB | 8,0 KB |
86-
| `isValidCbo` | códigos das ocupações da CBO 2002, sem os títulos | 6,6 KB | 1,7 KB |
87-
| `isValidCnae` | códigos da CNAE-Subclasses 2.3, sem as descrições | 4,5 KB | 1,9 KB |
88-
| `isValidCest` | códigos do CEST, sem as descrições | 3,5 KB | 0,8 KB |
89-
| `isValidNbs` | códigos da NBS 2.0, sem as descrições | 3,4 KB | 1,2 KB |
81+
| `isValidNcm` | códigos NCM (Nomenclatura Comum do Mercosul) | 29,6 KB | 9,0 KB |
82+
| `getBanks` · `getBankByCode` · `getBankByIspb` | participantes do STR do Banco Central (COMPE + ISPB) | 26,2 - 26,5 KB | 7,6 - 7,8 KB |
83+
| `getServiceItem` | lista de serviços da Lei Complementar 116/2003 | 25,5 KB | 8,2 KB |
84+
| `getIsbnInfo` · `formatIsbn` | faixas do ISBN da Agência Internacional do ISBN (RangeMessage) | 15,1 - 15,3 KB | 5,4 - 5,5 KB |
85+
| `isValidCbo` | códigos das ocupações da CBO 2002, sem os títulos | 6,7 KB | 1,7 KB |
86+
| `isValidCid10` | códigos das categorias e subcategorias da CID-10 V2008 mais os códigos `U07` do SIM, sem as descrições | 6,7 KB | 2,4 KB |
87+
| `isValidCnae` | códigos da CNAE-Subclasses 2.3, sem as descrições | 4,6 KB | 1,9 KB |
88+
| `isValidCest` | códigos do CEST, sem as descrições | 3,6 KB | 0,8 KB |
89+
| `isValidNbs` | códigos da NBS 2.0, sem as descrições | 3,5 KB | 1,3 KB |
9090

9191
A raiz do pacote é um único módulo ESM, então o bundler não consegue separar uma dessas bases de dados dele: importar um utilitário pesado da raiz coloca a base inteira no seu bundle principal, e um `import()` dinâmico da raiz não ajuda. Para carregar sob demanda, importe do subpath próprio:
9292

‎docs/pt-br/guides/state-city.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords: ["select de estado e cidade", "municípios do IBGE", "getMunicipalitie
66

77
Escolha um estado e as cidades dele preenchem o segundo select. Escolha o framework: cada exemplo roda o código logo abaixo dele, que pode ser copiado do jeito que está.
88

9-
O ponto aqui é quando cada tabela é carregada, e a resposta é: quando alguém abre o select que a mostra. Nem com a página, nem ao escolher um estado. Num formulário em que a cidade vem preenchida de outro lugar, ou é deixada em branco, os 148 KB de municípios nunca são buscados. Os estados são 27 linhas, 2,5 KB; os municípios são 5.571, 148 KB. Cada utilitário é um subpath, então `await import("@brazilian-utils/brazilian-utils/get-municipalities")` busca essa tabela e nada mais. Cada opção usa o `code` IBGE do município como valor e o `name` como rótulo, já que os nomes se repetem entre estados (existem dois "Pau D'Arco"). O bundler transforma isso num chunk separado, e o browser busca uma vez e guarda, então só a primeira abertura espera.
9+
O ponto aqui é quando cada tabela é carregada, e a resposta é: quando alguém abre o select que a mostra. Nem com a página, nem ao escolher um estado. Num formulário em que a cidade vem preenchida de outro lugar, ou é deixada em branco, os 76 KB de municípios nunca são buscados. Os estados são 27 linhas, 2,2 KB; os municípios são 5.571, 76 KB. Cada utilitário é um subpath, então `await import("@brazilian-utils/brazilian-utils/get-municipalities")` busca essa tabela e nada mais. Cada opção usa o `code` IBGE do município como valor e o `name` como rótulo, já que os nomes se repetem entre estados (existem dois "Pau D'Arco"). O bundler transforma isso num chunk separado, e o browser busca uma vez e guarda, então só a primeira abertura espera.
1010

1111

1212
<div class="example" data-name="React" data-demo="/snippets/live/?dir=state-city/react&example=state-city.tsx">

‎docs/pt-br/utilities.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@ Retorna os nomes das cidades brasileiras: todas as cidades, ou só as de um esta
20072007
- Ordenadas no locale "pt-BR".
20082008
- Qualquer `state` falsy pede a lista completa, enquanto `getMunicipalities` retorna `[]`.
20092009
- `state` ignora maiúsculas/minúsculas e espaços nas pontas: `'sp'` retorna as cidades de São Paulo, como `'SP'` (até a 2.4.0 retornava `[]`).
2010-
- Embute os 5571 nomes (~153,4 KB minificado, ~49,2 KB com gzip). Veja [Tamanho do bundle](pt-br/getting-started.md#tamanho-do-bundle) para carregá-la sob demanda via `@brazilian-utils/brazilian-utils/get-cities`.
2010+
- Embute os 5571 nomes (~64,2 KB minificado, ~26,4 KB com gzip). Veja [Tamanho do bundle](pt-br/getting-started.md#tamanho-do-bundle) para carregá-la sob demanda via `@brazilian-utils/brazilian-utils/get-cities`.
20112011
20122012
```javascript
20132013
import { getCities } from '@brazilian-utils/brazilian-utils';
@@ -3641,7 +3641,7 @@ Valida um código CID-10 contra as tabelas que o DATASUS publica, a edição bra
36413641
- Os dois níveis da classificação são válidos: as categorias de 3 caracteres (`A00`) e as subcategorias de 4 caracteres, escritas com o ponto (`A00.0`) ou sem ele (`A000`).
36423642
- Maiúsculas, minúsculas e espaços em volta são ignorados. Qualquer outra coisa (outro separador, um quinto caractere, um sufixo de cruz ou asterisco, um valor que não é string) é rejeitada.
36433643
- As tabelas são as V2008 do DATASUS, mais a categoria `U07` da tabela da CID-10 que o DATASUS mantém para o SIM (`U07`, `U07.0`, `U07.1` COVID-19 com vírus identificado e `U07.2` vírus não identificado), que as V2008 não têm. Um código que não está em nenhuma delas não é encontrado, como `U09.9` (condição pós-COVID-19) e `U10.9` (síndrome inflamatória multissistêmica associada à COVID-19). Até a 2.4.0 os códigos `U07` também não eram encontrados.
3644-
- Só uma tabela de códigos é lida (cerca de 26 KB minificada), não as descrições que `getCid10` carrega.
3644+
- Só uma tabela de códigos é lida (cerca de 7 KB minificada), não as descrições que `getCid10` carrega.
36453645
36463646
```javascript
36473647
import { isValidCid10 } from '@brazilian-utils/brazilian-utils';
@@ -3691,7 +3691,7 @@ Busca um código CID-10 e retorna a sua descrição oficial em português. O res
36913691
36923692
- Mesmas regras de entrada de `isValidCid10`. O `code` vem em maiúsculas e sem o ponto. Retorna `null` quando o código é desconhecido ou o valor não está em uma forma documentada.
36933693
- Mesma tabela de `isValidCid10`: a V2008 do DATASUS mais os códigos `U07` da tabela do SIM (`getCid10('U07.1')` é `{ code: 'U071', description: 'Infecção pelo novo Coronavírus (COVID-19)' }`); `U09.9` e `U10.9` não são encontrados.
3694-
- Este é o utilitário mais pesado do pacote: ele embute as 2046 categorias e 12191 subcategorias com suas descrições, cerca de 990 KB minificado (124 KB com gzip). Carregue-o sob demanda pelo seu subpath, como mostrado em [Tamanho do bundle](pt-br/getting-started.md#tamanho-do-bundle), e use `isValidCid10` quando a descrição não for necessária.
3694+
- Este é o utilitário mais pesado do pacote: ele embute as 2046 categorias e 12191 subcategorias com suas descrições, cerca de 722 KB minificado (113 KB com gzip). Carregue-o sob demanda pelo seu subpath, como mostrado em [Tamanho do bundle](pt-br/getting-started.md#tamanho-do-bundle), e use `isValidCid10` quando a descrição não for necessária.
36953695
36963696
```javascript
36973697
import { getCid10 } from '@brazilian-utils/brazilian-utils';

‎docs/snippets/state-city/angular/cities-of-state.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { StateCode } from "@brazilian-utils/brazilian-utils";
33

44
/**
55
* The municipalities of a state, fetched the first time that state's select is opened. The table is
6-
* 148 KB, so nothing is fetched until someone means to pick a city. What it is about is the state
6+
* 76 KB, so nothing is fetched until someone means to pick a city. What it is about is the state
77
* whose cities were asked for, so picking another state puts the resource back to waiting.
88
*
99
* A resource aborts a load it no longer wants and drops its answer, which is what the `abortSignal`

‎docs/snippets/state-city/angular/states.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { resource, type Signal } from "@angular/core";
22

33
/**
4-
* The states, fetched the first time the select is opened. 2.5 KB that a page whose visitor never
4+
* The states, fetched the first time the select is opened. 2.2 KB that a page whose visitor never
55
* opens it does not pay for, and the browser keeps the module once it has it. A resource stops
66
* with the component that asked and drops an answer it no longer wants.
77
*/

‎docs/snippets/state-city/react/use-cities-of-state.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Municipality, StateCode } from "@brazilian-utils/brazilian-utils";
33

44
/**
55
* The municipalities of a state, fetched the first time that state's select is opened. The table is
6-
* 148 KB, so nothing is fetched until someone means to pick a city, and the browser keeps the
6+
* 76 KB, so nothing is fetched until someone means to pick a city, and the browser keeps the
77
* module once it has it. `import()` takes no signal, so the module is not stopped, only what is
88
* done with it: a table that arrives for a state that is no longer picked, or after the component
99
* is gone, is dropped. The abort also forgets which state was asked for, so picking a state again

‎docs/snippets/state-city/react/use-states.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from "react";
22
import type { State } from "@brazilian-utils/brazilian-utils";
33

44
/**
5-
* The states, fetched the first time the select is opened. 2.5 KB that a page whose visitor never
5+
* The states, fetched the first time the select is opened. 2.2 KB that a page whose visitor never
66
* opens it does not pay for, and the browser keeps the module once it has it. `import()` takes no
77
* signal, so the module is not stopped, only what is done with it: a table that arrives after the
88
* component is gone is dropped.

‎docs/snippets/state-city/vanilla/state-city.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<script type="module">
1717
// Nothing is imported with the page. Opening a select is what says its list is wanted: the
18-
// states are 2.5 KB and the municipalities 148 KB, and the browser keeps each module once it has it.
18+
// states are 2.2 KB and the municipalities 76 KB, and the browser keeps each module once it has it.
1919
const CDN = "https://cdn.jsdelivr.net/npm/@brazilian-utils/brazilian-utils";
2020

2121
const states = document.getElementById("state");

0 commit comments

Comments
 (0)