Code Monkey home page Code Monkey logo

twpm's Introduction

twpm (twitter package manager)

https://gist.github.com/rauchg/5b032c2c2166e4e36713#gistcomment-1732501

Install

Check out the setup info (need twitter credentials)

npm i twpm -g

# use npx for one-off command
npx twpm install

Installing "packages"

twpm install https://twitter.com/rauchg/status/712799807073419264 --save left-pad

Usage (in code)

The default package folder/require prefix is @twpm/

// usage for `twpm install 712799807073419264 --save left-pad`
const leftPad = require("@twpm/left-pad");
leftPad(1, 5) // "00001"

Setup (2 ways)

Environment Variables

You need to add TWITTER_CONSUMER_KEY and TWITTER_CONSUMER_SECRET environment variables when running twpm

Config file (./twitter-config.js)

Create a config file at the root of your git repo.

You can create a Twitter app to get keys at https://apps.twitter.com.

module.exports = {
  "consumer_key": "",
  "consumer_secret": "",
  "app_only_auth": true,
};

Commands

Install

# will install to node_modules/@twpm/712799807073419264
twpm install 712799807073419264

# will install to node_modules/@twpm/712799807073419264
twpm install https://twitter.com/rauchg/status/712799807073419264

`twpm install` creates a `index.js` with transpiled source and a `package.json` with metadata (including the original source).

# Will install to node_modules/@twpm/left-pad
twpm install 712799807073419264 --save left-pad

# install everything under `twpm.dependencies` in `package.json`
twpm install

# shorthand
twpm i

Search

You can search through tweets that are hashtagged with #twpm and install them

# get some random ones
twpm search
# specific keyword search
twpm search left-pad

Tweets

Since twpm will be transpiling the code, twpm will strip out the first line if the tweet is multiline and contains the hashtag #twpm.

Tweet

@_henryzhu //#twpm:left-pad
export default (v, n, c = '0') => String(v).length >= n ? '' + v : (String(c).repeat(n) + v).slice(-n);

Extracted Code

// Input to be transpiled (just the function. otherwise an error will occur with decorators)
export default (v, n, c = '0') => String(v).length >= n ? '' + v : (String(c).repeat(n) + v).slice(-n);

Currently you will need to use a export default function() {} or export default () => {} in your tweet.

Config: twpm key in package.json

{
  "name": "your-app-here",
  "twpm": {
    "modulesLocation": "node_modules", // default folder
    "folderPrefix": "@twpm/", // default prefix
    "packageMetadata": [
      "name",
      "text",
      "screen_name",
      "id_str",
      "retweet_count",
      "favorite_count",
      "created_at",
      "user"
    ] // default fields to take from twitter status
    "dependencies": {
      "@twpm/left-pad": "712799807073419264"
      "@twpm/sort": "713782217646931968"
    }
  }
}

Example

left-pad

# twpm i 712799807073419264 --save left-pad
[email protected] /Users/hzoo/twpm-test

Tweet 712799807073419264: 359 ๐Ÿ”„, 632 ๐Ÿ’Ÿ
@rauchg at Thu Mar 24 00:34:51 +0000 2016
===
// ES6 leftPad
export default (v, n, c = '0') => String(v).length >= n ? '' + v : (String(c).repeat(n) + v).slice(-n);
---
- twpm-test
  - node_modules
    - @twpm
      - left-pad
        - index.js # transpiled index.js
        - package.json # reformatted twitter data + name field

twpm's People

Contributors

hzoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

twpm's Issues

installing 2x in a row

I think there's an issue if you run

npx twpm install 928128708862464001 --save mitt twice? not sure

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.