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

scb_wrapper

v1.0.3

Published

A wrapper for the SCB api

Downloads

10

Readme

SCB Wrapper

This is a nodejs wrapper for the Statistics Sweden (Statistiska centralbyrån) API. It can be located here SCB.

How to install

npm i scb_wrapper

How to use

There is a API Description to understand and use the api better.

To use the wrapper you need import the wrapper and instantiate the SCB class with either "sv" for swedish or "en" for english.

const scb_wrapper = require('scb_wrapper')

let scb = new scb_wrapper.SCB("sv")

The SCB class can also be instaniated with a variable amount of pre determined steps down the path.

let scb = new scb_wrapper.SCB("sv", "BE", "BE0001", "BE0001G", "BE0001T06AR")

getInfo() : Can be used to get the inforamtion of the current path.

scb.getInfo().then(res => {
    console.log(res)
})

moveDown(...path) : Can be used to move down the path to a specific node.

scb.moveDown(path)

Example:

scb.moveDown("BE")
scb.moveDown("BE0001")
//or do it directly
scb.moveDown("BE", "BE0001")

moveUp(steps) : Can be used to move up the path a speficic amount of steps.

scb.moveUp(steps)

Example:

scb.moveUp(1) or scb.moveUp() //to move up one step
scb.moveUp(3) //to move up three steps

moveToTop() : Can be used to move to the top node.

scb.moveToTop()

getCurrentPath() : Can be used to get the current path.

scb.getCurrentPath()

isLeafNode(response) : Can used to check if the current node is a leaf/end node. Will return true if the current node is a leaf node false otherwise.

scb.getInfo().then(resp => {
    console.log(scb.isLeafNode(res))
});

getVariables() : Can be used to get all the possible variables that can be used for a query request. Can only be used at leaf node.

scb.getVariables().then(res => {
    console.log(res)
})

getVariablesCodes() : Can be used to get all the variables code/keys for a query request. Can only be used at leaf node.

scb.getVariablesCodes().then(res => {
    console.log(res)
})

getVariableValuesFromText(text) : Can be used to get a all the variables for a specific code/key. Can only be used at leaf node.

scb.getVariableValuesFromText(variableCode).then(res => {
    console.log(res)
})

Example:

let  scb = new  functions.SCB("sv", "BE", "BE0001", "BE0001G", "BE0001T06AR")

scb.getVariableValuesFromText("tilltalsnamn").then(res => {
    console.log(res)
})//Will return all the available values for the key "tilltalsnamn"

setQuery(parameters) : Can be used to set a query that can be used to make a post request. The in parameters is a json formated object contaning the key/code and variable combos that is to be used in the query.

scb.setQuery(parameters).then(response  => {
})

Example:

let  scb = new  functions.SCB("sv", "BE", "BE0001", "BE0001G", "BE0001T06AR")

let parameters = [
{"tilltalsnamn" : ["Niklas"]},
{"tabellinnehåll" : ["Antal bärare"]},
{"år" : ["2021"]},
]

scb.setQuery(parameters).then(response  => {
})

getQuery() : Can be used to get the currently set query.

scb.getQuery()

clearQuery() : Can be used to clear the currently set query.

scb.clearQuery()

setQueryResponseFormat(format) : Can be used to set the response format that will be used when making a post request.

scb.setQueryResponseFormat(format)

Example:

scb.setQueryResponseFormat("json")

getValidFormats() : Can be used to get all the valid repsonse formats available.

scb.getValidFormats()

getData() : Can be used to get data from the currently set query.

scb.getData().then(res => {
    console.log(res)
})

Example:

let  scb = new  functions.SCB("sv", "BE", "BE0001", "BE0001G", "BE0001T06AR")

let parameters = [
{"tilltalsnamn" : ["Niklas"]},
{"tabellinnehåll" : ["Antal bärare"]},
{"år" : ["2021"]},
]

scb.setQuery(parameters).then(response  => {
    scb.getData().then(res => {
        console.log(res)
    })
})

getDataFromQuery(parameters, readable, format) : Can be used to get the data directly with the from the parameters that a used. Readable is a boolean to be used to determind if the response should be in human readable text or not.

scb.getDataFromQuery(parameters, readable, format).then(res => {
    console.log(res)
})

Example:

let  scb = new  functions.SCB("sv", "BE", "BE0001", "BE0001G", "BE0001T06AR")

let parameters = [
{"tilltalsnamn" : ["Niklas"]},
{"tabellinnehåll" : ["Antal bärare"]},
{"år" : ["2021"]},
]

scb.getDataFromQuery(parameters, true, "json").then(res => {
    console.log(JSON.stringify(res))
}) // Will return how many were named Niklas in the year 2021

Insperation

The insperation for this nodejs wrapper come from the python SCB wrapper pyscbwrapper.