open-index/open-npm huggingface dataset:
npm package: @kth/http-responses
Description: Simpel standardized http responses.
Author: KTH
Latest version: 1.0.84

# HTTP Responses ![alt text](https://api.travis-ci.org/KTH/http-responses.svg?branch=master) ![Continous Integration](https://github.com/KTH/http-responses/actions/workflows/main.yml/badge.svg)

Npm: `@kth/http-responses`

Simple ways of returning responses in a declarative way without status codes.
Note that it is not async so use it for simple smal stuff.


## Demo application

[Demo code source here](https://github.com/KTH/http-responses/tree/master/demo-app/).


```javascript
const express = require("express");
const httpResponse = require("@kth/http-responses");
const app = express();

app.get("/", function (request, response) {
  httpResponse.ok(request, response, "<!DOCTYPE html><h1>Hello world!<h1>");
});

app.get("/_monitor", function (request, response) {
  httpResponse.ok(
    request,
    response,
    "APPLICATION_STATUS: OK",
    httpResponse.contentTypes.PLAIN_TEXT
  );
});

app.get("/error5xx.html", function (request, response) {
  httpResponse.internalServerError(request, response, "Internal Server Error");
});

app.get("/favicon.ico", function (request, response) {
  httpResponse.noContent(request, response);
});

app.use(function (request, response) {
  httpResponse.notFound(request, response, "Page not found");
});

app.listen(80, function () {
  console.log("Server started");
});
```

```json
{
  "name": "Demo",
  "version": "1.0.0",
  "description": "Demo app for @kth/http-responses",
  "main": "index.js",
  "scripts": {
    "clean": "rm -r ./node_modules && rm package-lock.json"
  },
  "author": "paddy@kth.se",
  "license": "MIT",
  "dependencies": {
    "@kth/http-responses": "^1.0.20",
    "express": "^4.17.1"
  }
}
```
npm package: @kth/in-memory-cache
Description: 0.1.1 Basic in memory cache for primitives and objects.
Author: KTH
Latest version: 0.1.53

# In-memory Cache ![Continous Integration](https://github.com/KTH/in-memory-cache/actions/workflows/main.yml/badge.svg)

Npm: `@kth/in-memory-cache`

This is how you use the in-memory cache. It is a very basic iplementation.

```javascript

const cache = require("@kth/in-memory-cache");

const user = { firstName: "John", lastname: "Doe" }

cache.add('user-id', user);

if (cache.isValid('user-id')) {
    console.log('Users lastname is ' + cache.get('user-id').lastname);
}

cache.remove('user-id');
```

## TTL - Set the time an item is valid

If a cache item should live for a long time you can set a time to live (TTL) on it in milliseconds on the item.

```javascript
const cache = require('@kth/in-memory-cache');

const aDay = 1000 * 60 * 60 * 24;
const user = { firstName: 'John', lastname: 'Doe' }

cache.add('long-caching-object', user, aDay);
```

## Limit the number of items in the store

Sometimes you whould like to limit the number of items that are stored in the cache.
This is not a FIFO, if there is space, the item will be added. Otherwise silently ignored.

```javascript
const cache = require('@kth/in-memory-cache');

cache.setMaxSlots(2)

cache.add('key-1', 'value 1');
cache.add('key-2', 'value 2');
cache.add('key-3', 'value 3'); // not added, with logger.info(str) message

cache.length(); // 2
```

## Use your own logger

Your project probably already have a logging framework, you can pass it to the cache.
The default logger is console.

```javascript
const cache = require('@kth/in-memory-cache');
const log = require('someLogger')

// The logger needs to implement the function info(string)
cache.setLogger(log);

```


## Run tests

To run the tests, do npm magic or run `./build.sh`. You can also view the tests at https://travis-ci.org/KTH/in-memory-cache

```bash
npm install
npm test
```

```text
  Cache - Add
    ✓ 'Null' is an acceptable cache item value.
    ✓ 'Undefined' is an acceptable cache item value.
    ✓ When no TTL is passed, the default 1000ms is used as the time for an item to live.
    ✓ Use a specific TTL for an item to live.
    ✓ When a max slot is set no more items are added, until old ones are removed.

  Cache - Get
    ✓ It is possible to store and get a string.
    ✓ It is possible to store and get a number.
    ✓ It is possible to store and get an object.
    ✓ If the TTL has expired, 'undefined' will be returend for the item key.
    ✓ If there is no matching item in the store 'undefined' will be returned.

  Cache - Remove
    ✓ It is possible to remove one specific item in the cache.
    ✓ It is possible to remove all items in the cache.
    ✓ Nothing happens if you remove an item that is not in the store.

  Cache - Number of slots
    ✓ It is possible to get the numer of items in the cache.
    ✓ It is possible to set the maximum number of items in the cache.

  Cache - logger
    ✓ It is possible to set an external logger.

```
npm package: @kth/kth-ckeditor-build
Description: Custom build of the CKEditor for use in KTH websites.
Author: KTH Team Webb
Latest version: 4.0.14

# KTH CKEditor build

> **_Do not manually edit files in the `ckeditor` folder!_**

This project contains a custom build of the [CKEditor][ckeditor].

To update the CKEditor code, [go to the builder][ckeditorbuilder] and
upload the `ckeditor/build-config.js` file to reuse the same settings
and plugins. Download ZIP file, delete the current `ckeditor` folder,
unpack the ZIP file into this repository, and finally commit and push.
Also don't forget to update the version using the `npm version` command.

When installing this project through npm, run the following command:

```bash
npm install --save-dev @kth/kth-ckeditor-build
```

In the module there is a gulp (version 4) task generator which can copy CKEditor files to the your project target directory.
They move the plugin as well as a configuration file into your project directory.
Here is an example how it can be used.

```
const ckGulp = require('@kth/kth-ckeditor-build/gulpfile')
const ckEditorBuild = ckGulp.buildTask(
  gulp,
  './node_modules/@kth/kth-ckeditor-build',
  './dist/js/ckeditor',
  'profiles-web'
)

// if there is a vendor task, you can add it there
gulp.task(
  'vendor',
  gulp.series([ckEditorBuild, vendor], done => {
    done()
  })
)

// or define as a standalone task which can  then added to the final build task
gulp.task(
  'ckEditorBuild',
  gulp.series([ckEditorBuild], done => {
    done()
  })
)
```

In order for the configuration file to be used, it has to be configured in the client.
For example in your page view module. Attention: for Bootstrap formatting in the editor,
provide a Bootstrap CSS path in the contentsCss array.
This also a good place to override options that may be needed for your project

```javascript
CKEDITOR.replace('editor', {
  customConfig: 'customConfig.js',
  contentsCss: [CKEDITOR.getUrl('contents.css'), 'path-to-bootstrap-css'],
  // We need more height, lets override! height: 1337
})
```

Finally, reference the CKEditor JavaScript file `ckeditor/ckeditor.js`
and optionally `ckeditor/adapters/jquery.js` if you are using jQuery.

To test the editor without installing, clone this repository and run
`npm run server` and open [http://localhost:5050][local] in your browser.

## Note about the link dialog

Currently this works perfectly fine as it is. However, the link dialog
is missing a way to edit the link text. Right now, the best way to
ensure a specific link text is to first type out the text, then
highlight it, then open the link dialog, enter a URL, and click OK. It
is being worked on by the CKEditor team, but it's not certain when it's
finished.

## Sample config

For a sample config, check out the [server/public/js/index.js][sample]
file.

[ckeditor]: http://ckeditor.com
[ckeditorbuilder]: http://ckeditor.com/builder
[local]: http://localhost:5050
[sample]: server/public/js/index.js
npm package: @kth/kth-node-docx
Description: A docx export module for Node.js applications.
Author: KTH
Latest version: 2.0.4
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# docx generator

Given a `docx` file with the following content:

```
{@publications}
```

And an XML string generated with the `template` and/or `docx` helpers:

```xml
<w:p><w:r><w:t>hello world</w:t></w:r></w:p>
```

## Code usage

```javascript
var fs = require('fs')
var docx = require('@kth/kth-node-docx')
var xml = '<w:p><w:r><w:t>hello world</w:t></w:r></w:p>'
var templateBuffer = fs.readFileSync('template.docx', 'binary')
var outputBuffer = docx.generate(xml, templateBuffer, 'publications')
fs.writeFileSync('publications.docx', outputBuffer)
```

For an example of how to use the XML helpers, see the
`test/integration.js` file.
npm package: @kth/kth-node-react-common
Description: Common utility functions and components for React-based node-web projects
Author: KTH
Latest version: 1.0.32
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# kth-node-react-common ![alt text](https://api.travis-ci.org/KTH/kth-node-react-common.svg?branch=main)

KTH Stockholm has several applications which are based on React and support server-side rendering with Node.js, e.g. some smaller parts of https://www.kth.se. This package contains common utility functions and components used by those applications.

# Installation

- Install the package:

  ```js
  npm install @kth/kth-node-react-common
  ```

- Install the peer-dependencies of the package:

  ```js
  npm install axios react prop-types
  ```

# How to use

- Option 1: Import parts of the package and destructure them then:

  ```js
  // Examples (ES6 style):
  import { Utils, Components, FormComponents, MobxUtils } from '@kth/kth-node-react-common'

  const { ensureObject } = Utils
  const { Breadcrumbs, SystemMessage } = Components
  const { useDataBag, Input } = FormComponents
  const { useStore } = MobxUtils
  ```

  ```js
  // Examples (CommonJS style):
  const { Utils, Components, FormComponents, MobxUtils } = require('@kth/kth-node-react-common')

  const { ensureObject } = Utils
  const { Breadcrumbs, SystemMessage } = Components
  const { useDataBag, Input } = FormComponents
  const { useStore } = MobxUtils
  ```

- Option 2: Import sub-directory of the package and destructure them directly:

  ```js
  // Examples (ES6 style):
  import { ensureObject } from '@kth/kth-node-react-common/utils'
  import { Breadcrumbs, SystemMessage } from '@kth/kth-node-react-common/components'
  import { useDataBag, Input } from '@kth/kth-node-react-common/FormComponents'
  import { useStore } from '@kth/kth-node-react-common/MobxUtils'
  ```

  ```js
  // Examples (CommonJS style):
  const { ensureObject } = require('@kth/kth-node-react-common/utils')
  const { Breadcrumbs, SystemMessage } = require('@kth/kth-node-react-common/components')
  const { useDataBag, Input } = require('@kth/kth-node-react-common/FormComponents')
  const { useStore } = require('@kth/kth-node-react-common/MobxUtils')
  ```

- Option 3: Import parts of the package, destructure them twice directly:

  > This is only possible with CommonJS style imports.

  ```js
  // Examples (CommonJS style):
  const { ensureObject } = require('@kth/kth-node-react-common').Utils
  const { Breadcrumbs, SystemMessage } = require('@kth/kth-node-react-common').Components
  const { useDataBag, Input } = require('@kth/kth-node-react-common').FormComponents
  const { useStore } = require('@kth/kth-node-react-common').MobxUtils
  ```

# Package content

The different parts of this package are described in detail in the following Markdown files:

- [MobxUtils](./MOBXUTILS.md)
- Other utilities (tbd.)
- Helper components (tbd.)
- FormHelper components (tbd.)
npm package: @kth/kth-search-push-util
Description: Utils to simplifie pushing information to KTH:s search solution
Author: KTH
Latest version: 2.1.0

# kth-search-push-util

Utils to simplifie pushing information to KTH:s search solution

### Examples

```javascript
const log = require('kth-node-log')
const { SearchPush } = require('@kth/kth-node-search-push-util')

const config = {
  log: log,
  client: api.client,
  paths: api.paths,
  batchSize: 10
}

const util = new SearchPush(config)

const import = async (pages) => {
  for (let page of pages) {
    await util.pushPage(page)
  }

  await util.flush()

  await cleanup()
}

const cleanup = () => {
  return util.deletePages('type', new Date())
}

```
npm package: @kth/kth-style-react-components
Description: Library with react components implemented with KTH style
Author: KTH
Latest version: 2.0.20
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# KTH Style - React Components

![Travis status](https://api.travis-ci.org/KTH/kth-style-react-components.svg?branch=master)

## Description

This project is a work in progress.

**As of 2021-02-12 we shall reboot this project. The new version (2.0) will do a new take on the components and also support Formik.**

The purpose is to create an easy to use library in React with common components implemented with KTH style.

## Get started

Install @kth/kth-style-react-components

```
npm i @kth/kth-style-react-components
```

Import the component in the file where you want to use it, in this example, we want to import Header

```
import { Header } from '@kth/kth-style-react-components'
```

Use it just like any React component

Example:

```
import React from 'react'
import { Header } from '@kth/kth-style-react-components'

export const App = () => {
  return <div>
    <Header />
    ...
  </div>
}
```
npm package: @kth/kth-validation
Description: Validation utils commonly used in KTH Node projects
Author: pontusn@kth.se
Latest version: 1.0.0

# KTH Validation

Validation utils commonly used in KTH Node projects

## Example

```javascript

const { required } = require('@kth/kth-validation')

function aFunction(name, occupation) {
  required({name, occupation})

  // .. do magic things
}

// No errors
aFunction('John', 'Painter')

// Error is thrown
aFunction('John')

```
npm package: @kth/ladok-api
Description: Wrapper for "got" to interact with the Ladok API
Author: KTH Royal Institute of Technology
Latest version: 0.3.1
Deprecated: This code should be inlined in lms-export-to-ladok

# ladok-api

> This project version is currently 0.x, meaning that any update can cause any breaking change in its API without any announcement

## Usage

``` javascript
const LadokApi = require('@kth/ladok-api')
const fs = require('fs')

;(async function start () {
  const ladok = LadokApi(process.env.LADOK_API_BASE_URL, {
    pfx: fs.readFileSync('./my-certificate.pfx'),
    passphrase: process.env.LADOK_API_CERT_PASSPHRASE
  })

  console.log((await ladok.test()).body)
})()
```

## API

### LadokApi(baseUrl, sslOptions)

Returns a LadokApi instance. Two arguments are required:

1. `baseUrl`. The base URL for calls performed by the instance.
2. `sslOptions`. An object containing the SSL certificate provided by Ladok.

   - If you have a *.pfx* file, pass it in `pfx`
   - If you have a *.cert* file **and** the *.key*, pass them in `cert` and `key`.
   - Additionally, pass a `passphrase` if needed.

``` javascript
const ladok = LadokApi(process.env.LADOK_API_BASE_URL, {
  pfx: fs.readFileSync('./my-certificate.pfx'),
  passphrase: process.env.LADOK_API_CERT_PASSPHRASE
})
```

## Instance methods

### ladokApi.test()

Make a request to the `/kataloginformation/anvandare/autentiserad`  endpoint in Ladok. Useful when you want to check that you have set up the environment properly.

If everything goes well, it returns a string with the response of the mentioned endpoint.

``` javascript
const response = (await ladok.test()).body
```

### ladokApi.requestUrl(endpoint, method, parameters)

Make a request to a certain `endpoint` with a specific `method`. Use `parameters` (the third argument) to pass body parameters.

### ladokApi.sok(endpoint, criteria, key)

Make a "sok"-type request to Ladok. Parameters:

1. `endpoint`. The endpoint to do the request.
2. `criteria`. Object to pass as search criteria. It will be passed as body parameters in the request.
3. `key`. Key in the response object that contains the array to traverse.

Returns an iterator object to traverse through each of the results.