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

sakwesakwe

v1.0.0

Published

## Goal * You have a list of Question Answer pairs and * You have to create a system that consumes the list then answer asked questions using the list

Downloads

4

Readme

Sakwe Sakwe

Goal

  • You have a list of Question Answer pairs and
  • You have to create a system that consumes the list then answer asked questions using the list

Step by Step

  • Decide on what technology stack to use

    • The system is a nodejs package
    • We use Typescript as the coding language
    • We use Gulp as the build system (along with Typescript and Babel plugins)
    • We use jest for testing
  • Initialize the project

# in your terminal
mkdir sakwesakwe
cd sakwesakwe
npm init -y
  • Create the project structure
/-
 | - __tests__
    | - index.js # we test javascript usage
    | - index.ts # Make sure our package can be used in other typescript projects
 | - src
    | - index.ts
 | - dist
    | - index.js
  • Install development related packages
npm install --save-dev typescript
npm install --save-dev @types/node
npm install --save-dev gulp-cli
npm install --save-dev gulp
npm install --save-dev gulp-sourcemaps
npm install --save-dev gulp-typescript
npm install --save-dev gulp-babel babel-plugin-transform-runtime babel-preset-es2015
npm install --save-dev jest
npm install --save-dev ts-jest @types/jest
  • Create Typescript configuration file tsconfig.json
// inside package.json
{
...
    "scripts": {
...
        "tsc:init": "node ./node_modules/typescript/lib/tsc --init",
        "tsc:compile": "node ./node_modules/typescript/lib/tsc"
...
    }
...    
}
npm run tsc:init
  • Modify the Typescript config file tsconfig.json so that it compiles to es6
{
...
    "compilerOptions": {
        "target": "es6"
    }
...
}
  • Add Jest configuration info to package.json
// inside package.json
{
...
    "scripts": {
...
        "test": "jest"
...
    }
...
  "jest": {
    "transform": {
      ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ]
  }
...
}
  • Create a gulpfile.js
touch gulpfile.js
  • Add script content to the Gulp file
var gulp = require('gulp');  
var sourcemaps = require('gulp-sourcemaps');  
var ts = require('gulp-typescript');  
var babel = require('gulp-babel');

var tsProject = ts.createProject('./tsconfig.json');

gulp.task('default', function() {  
    return gulp.src('src/**/*.ts')
        .pipe(sourcemaps.init())
        .pipe(ts(tsProject))
        .pipe(babel({
            presets: ['es2015', 'transform-runtime']
        }))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('dist'));
});
  • Create a test for Javascript usage
touch __tests__/index.js
// inside __tests__/index.js
describe('matching cities to foods', function() {
    beforeEach(function() {
        console.log('About to run the index.js test');
    });
    // question: where is drake from?
    // answers: 'Canada', 'Toronto, Canada'
    test('the asked question has an answer', function() {
        var question = 'where is drake from?';
        var answers: ['Canada', 'Toronto', 'Toronto, Canada']
        var QASource = [{ 
            question: question, 
            answers: answers
        }];
        var sakwesakwe = new Sakwesakwe(QASource);
        var predictedAnswer = sakwesakwe.ask(question);
        var realAnswers = answers;
        expect(realAnswers).toContain(predictedAnswer);
    });
});
  • Create a test for Typescript usage
touch __tests__/index.ts
// inside __tests__/index.ts
describe('matching cities to foods', () => {
    beforeEach(() => {
        console.log('About to run the index.js test');
    });
    // question: where is drake from?
    // answers: 'Canada', 'Toronto, Canada'
    test('the asked question has an answer', () => {
        const question = 'where is drake from?';
        let answers: ['Canada', 'Toronto', 'Toronto, Canada']
        var QASource = [{ question, answers }];
        let sakwesakwe = new Sakwesakwe(QASource);
        let predictedAnswer = sakwesakwe.ask(question);
        let realAnswers = answers;
        expect(realAnswers).toContain(predictedAnswer);
    });
});
  • Run the tests They should fail
npm test
  • Write the required logic