grab 0.0.7 → 0.0.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ /*! tailwindcss v4.1.17 | MIT License | https://tailwindcss.com */
2
+ @layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scale-z:1;--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial;--tw-tracking:initial;--tw-ordinal:initial;--tw-slashed-zero:initial;--tw-numeric-figure:initial;--tw-numeric-spacing:initial;--tw-numeric-fraction:initial;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-duration:initial;--tw-ease:initial;--tw-contain-size:initial;--tw-contain-layout:initial;--tw-contain-paint:initial;--tw-contain-style:initial}}}@layer theme{:root,:host{--font-sans:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--color-black:#000;--color-white:#fff;--spacing:.25rem;--font-weight-medium:500;--radius-xs:.125rem;--ease-out:cubic-bezier(0,0,.2,1);--animate-pulse:pulse 2s cubic-bezier(.4,0,.6,1)infinite;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4,0,.2,1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono);--color-grab-pink:#b21c8e;--color-grab-purple:#d239c0;--color-label-tag-border:#730079;--color-label-muted:#767676}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-auto{pointer-events:auto}.pointer-events-none{pointer-events:none}.visible{visibility:visible}.absolute{position:absolute}.fixed{position:fixed}.top-0{top:calc(var(--spacing)*0)}.left-0{left:calc(var(--spacing)*0)}.z-2147483645{z-index:2147483645}.z-2147483646{z-index:2147483646}.z-2147483647{z-index:2147483647}.z-\[2147483645\]{z-index:2147483645}.container{width:100%}@media (min-width:40rem){.container{max-width:40rem}}@media (min-width:48rem){.container{max-width:48rem}}@media (min-width:64rem){.container{max-width:64rem}}@media (min-width:80rem){.container{max-width:80rem}}@media (min-width:96rem){.container{max-width:96rem}}.m-0{margin:calc(var(--spacing)*0)}.-mt-px{margin-top:-1px}.-ml-\[2px\]{margin-left:-2px}.ml-1{margin-left:calc(var(--spacing)*1)}.box-border{box-sizing:border-box}.flex{display:flex}.grid{display:grid}.hidden{display:none}.size-fit{width:fit-content;height:fit-content}.h-0{height:calc(var(--spacing)*0)}.h-4{height:calc(var(--spacing)*4)}.h-5{height:calc(var(--spacing)*5)}.h-5\.5{height:calc(var(--spacing)*5.5)}.h-\[7px\]{height:7px}.h-\[17px\]{height:17px}.h-\[18px\]{height:18px}.h-fit{height:fit-content}.min-h-0{min-height:calc(var(--spacing)*0)}.min-h-4{min-height:calc(var(--spacing)*4)}.w-0{width:calc(var(--spacing)*0)}.w-0\.5{width:calc(var(--spacing)*.5)}.w-1{width:calc(var(--spacing)*1)}.w-\[7px\]{width:7px}.w-\[17px\]{width:17px}.w-auto{width:auto}.w-fit{width:fit-content}.w-full{width:100%}.max-w-\[280px\]{max-width:280px}.flex-1{flex:1}.shrink{flex-shrink:1}.shrink-0{flex-shrink:0}.-translate-x-1\/2{--tw-translate-x:calc(calc(1/2*100%)*-1);translate:var(--tw-translate-x)var(--tw-translate-y)}.-translate-y-1\/2{--tw-translate-y:calc(calc(1/2*100%)*-1);translate:var(--tw-translate-x)var(--tw-translate-y)}.scale-75{--tw-scale-x:75%;--tw-scale-y:75%;--tw-scale-z:75%;scale:var(--tw-scale-x)var(--tw-scale-y)}.scale-100{--tw-scale-x:100%;--tw-scale-y:100%;--tw-scale-z:100%;scale:var(--tw-scale-x)var(--tw-scale-y)}.transform{transform:var(--tw-rotate-x,)var(--tw-rotate-y,)var(--tw-rotate-z,)var(--tw-skew-x,)var(--tw-skew-y,)}.animate-pulse{animation:var(--animate-pulse)}.cursor-crosshair{cursor:crosshair}.cursor-pointer{cursor:pointer}.resize{resize:both}.resize-none{resize:none}.flex-col{flex-direction:column}.items-center{align-items:center}.items-end{align-items:flex-end}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.gap-0\.5{gap:calc(var(--spacing)*.5)}.gap-1{gap:calc(var(--spacing)*1)}.gap-\[3px\]{gap:3px}.gap-\[5px\]{gap:5px}.gap-px{gap:1px}.self-stretch{align-self:stretch}.overflow-hidden{overflow:hidden}.overflow-y-auto{overflow-y:auto}.rounded-\[1\.5px\]{border-radius:1.5px}.rounded-\[1px\]{border-radius:1px}.rounded-full{border-radius:3.40282e38px}.rounded-xs{border-radius:var(--radius-xs)}.rounded-t-none{border-top-left-radius:0;border-top-right-radius:0}.rounded-b-xs{border-bottom-right-radius:var(--radius-xs);border-bottom-left-radius:var(--radius-xs)}.border{border-style:var(--tw-border-style);border-width:1px}.\[border-width\:0\.5px\]{border-width:.5px}.\[border-top-width\:0\.5px\]{border-top-width:.5px}.border-none{--tw-border-style:none;border-style:none}.border-solid{--tw-border-style:solid;border-style:solid}.border-\[\#7e0002\]{border-color:#7e0002}.border-\[\#B3B3B3\]{border-color:#b3b3b3}.border-grab-purple{border-color:var(--color-grab-purple)}.border-grab-purple\/40{border-color:#d239c066}@supports (color:color-mix(in lab, red, red)){.border-grab-purple\/40{border-color:color-mix(in oklab,var(--color-grab-purple)40%,transparent)}}.border-grab-purple\/50{border-color:#d239c080}@supports (color:color-mix(in lab, red, red)){.border-grab-purple\/50{border-color:color-mix(in oklab,var(--color-grab-purple)50%,transparent)}}.border-label-tag-border{border-color:var(--color-label-tag-border)}.border-white{border-color:var(--color-white)}.border-t-\[\#D9D9D9\]{border-top-color:#d9d9d9}.bg-\[\#F7F7F7\]{background-color:#f7f7f7}.bg-black{background-color:var(--color-black)}.bg-grab-pink{background-color:var(--color-grab-pink)}.bg-grab-purple{background-color:var(--color-grab-purple)}.bg-grab-purple\/5{background-color:#d239c00d}@supports (color:color-mix(in lab, red, red)){.bg-grab-purple\/5{background-color:color-mix(in oklab,var(--color-grab-purple)5%,transparent)}}.bg-grab-purple\/8{background-color:#d239c014}@supports (color:color-mix(in lab, red, red)){.bg-grab-purple\/8{background-color:color-mix(in oklab,var(--color-grab-purple)8%,transparent)}}.bg-transparent{background-color:#0000}.bg-white{background-color:var(--color-white)}.p-0{padding:calc(var(--spacing)*0)}.p-1{padding:calc(var(--spacing)*1)}.px-0{padding-inline:calc(var(--spacing)*0)}.px-1\.5{padding-inline:calc(var(--spacing)*1.5)}.px-2{padding-inline:calc(var(--spacing)*2)}.px-\[2px\]{padding-inline:2px}.px-\[3px\]{padding-inline:3px}.py-0{padding-block:calc(var(--spacing)*0)}.py-\[2px\]{padding-block:2px}.py-\[3px\]{padding-block:3px}.py-\[5px\]{padding-block:5px}.py-px{padding-block:1px}.pt-1{padding-top:calc(var(--spacing)*1)}.pt-1\.5{padding-top:calc(var(--spacing)*1.5)}.pr-1{padding-right:calc(var(--spacing)*1)}.pr-1\.5{padding-right:calc(var(--spacing)*1.5)}.pb-1{padding-bottom:calc(var(--spacing)*1)}.pl-1\.5{padding-left:calc(var(--spacing)*1.5)}.align-middle{vertical-align:middle}.font-\[ui-monospace\,\'SFMono-Regular\'\,\'SF_Mono\'\,\'Menlo\'\,\'Consolas\'\,\'Liberation_Mono\'\,monospace\]{font-family:ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace}.font-mono{font-family:var(--font-mono)}.font-sans{font-family:var(--font-sans)}.text-\[11\.5px\]{font-size:11.5px}.text-\[11px\]{font-size:11px}.text-\[12px\]{font-size:12px}.leading-3\.5{--tw-leading:calc(var(--spacing)*3.5);line-height:calc(var(--spacing)*3.5)}.leading-4{--tw-leading:calc(var(--spacing)*4);line-height:calc(var(--spacing)*4)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.tracking-\[-0\.04em\]{--tw-tracking:-.04em;letter-spacing:-.04em}.tracking-\[-0\.08em\]{--tw-tracking:-.08em;letter-spacing:-.08em}.wrap-break-word{overflow-wrap:break-word}.whitespace-normal{white-space:normal}.text-\[\#0C0C0C\]{color:#0c0c0c}.text-\[\#47004A\]{color:#47004a}.text-\[\#71717a\]{color:#71717a}.text-\[\#B91C1C\]{color:#b91c1c}.text-\[\#c00002\]{color:#c00002}.text-black{color:var(--color-black)}.text-black\/50{color:#00000080}@supports (color:color-mix(in lab, red, red)){.text-black\/50{color:color-mix(in oklab,var(--color-black)50%,transparent)}}.text-label-muted{color:var(--color-label-muted)}.text-label-tag-border{color:var(--color-label-tag-border)}.text-white{color:var(--color-white)}.tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal,)var(--tw-slashed-zero,)var(--tw-numeric-figure,)var(--tw-numeric-spacing,)var(--tw-numeric-fraction,)}.antialiased{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.opacity-0{opacity:0}.opacity-50{opacity:.5}.opacity-100{opacity:1}.opacity-\[0\.99\]{opacity:.99}.brightness-125{--tw-brightness:brightness(125%);filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.filter{filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.filter-\[drop-shadow\(0px_0px_4px_\#51515180\)\]{filter:drop-shadow(0 0 4px #51515180)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-\[grid-template-rows\]{transition-property:grid-template-rows;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-\[width\,height\]{transition-property:width,height;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-all{transition-property:all;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-opacity{transition-property:opacity;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-none{transition-property:none}.duration-30{--tw-duration:30ms;transition-duration:30ms}.duration-100{--tw-duration:.1s;transition-duration:.1s}.duration-150{--tw-duration:.15s;transition-duration:.15s}.duration-300{--tw-duration:.3s;transition-duration:.3s}.ease-out{--tw-ease:var(--ease-out);transition-timing-function:var(--ease-out)}.will-change-\[transform\,width\,height\]{will-change:transform,width,height}.contain-layout{--tw-contain-layout:layout;contain:var(--tw-contain-size,)var(--tw-contain-layout,)var(--tw-contain-paint,)var(--tw-contain-style,)}.outline-none{--tw-outline-style:none;outline-style:none}.select-none{-webkit-user-select:none;user-select:none}.\[font-synthesis\:none\]{font-synthesis:none}@media (hover:hover){.hover\:scale-105:hover{--tw-scale-x:105%;--tw-scale-y:105%;--tw-scale-z:105%;scale:var(--tw-scale-x)var(--tw-scale-y)}.hover\:bg-\[\#F5F5F5\]:hover{background-color:#f5f5f5}.hover\:bg-\[\#FEF2F2\]:hover{background-color:#fef2f2}.hover\:opacity-100:hover{opacity:1}}}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}@property --tw-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-z{syntax:"*";inherits:false;initial-value:0}@property --tw-scale-x{syntax:"*";inherits:false;initial-value:1}@property --tw-scale-y{syntax:"*";inherits:false;initial-value:1}@property --tw-scale-z{syntax:"*";inherits:false;initial-value:1}@property --tw-rotate-x{syntax:"*";inherits:false}@property --tw-rotate-y{syntax:"*";inherits:false}@property --tw-rotate-z{syntax:"*";inherits:false}@property --tw-skew-x{syntax:"*";inherits:false}@property --tw-skew-y{syntax:"*";inherits:false}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-tracking{syntax:"*";inherits:false}@property --tw-ordinal{syntax:"*";inherits:false}@property --tw-slashed-zero{syntax:"*";inherits:false}@property --tw-numeric-figure{syntax:"*";inherits:false}@property --tw-numeric-spacing{syntax:"*";inherits:false}@property --tw-numeric-fraction{syntax:"*";inherits:false}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false}@property --tw-duration{syntax:"*";inherits:false}@property --tw-ease{syntax:"*";inherits:false}@property --tw-contain-size{syntax:"*";inherits:false}@property --tw-contain-layout{syntax:"*";inherits:false}@property --tw-contain-paint{syntax:"*";inherits:false}@property --tw-contain-style{syntax:"*";inherits:false}@keyframes pulse{50%{opacity:.5}}
package/package.json CHANGED
@@ -1,28 +1,72 @@
1
1
  {
2
- "author": "Andrew Luetgers <andrew.luetgers@gmail.com> (http://www.andrewluetgers.com/)",
3
- "name": "grab",
4
- "description": "Makes grabbing values out of complex objects simpler.",
5
- "version": "0.0.7",
6
- "homepage": "https://github.com/andrewluetgers/grab.js",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/andrewluetgers/grab.js"
10
- },
11
- "bugs": "https://github.com/andrewluetgers/grab.js/issues",
12
- "main": "./lib/grab.js",
13
- "keywords": [
14
- "value",
15
- "object",
16
- "json",
17
- "query",
18
- "path",
19
- "default"
20
- ],
21
- "engines": {
22
- "node": "*"
23
- },
24
- "dependencies": {
25
- "underscore": ">= 1.4.x"
26
- },
27
- "license": "MIT"
2
+ "name": "grab",
3
+ "version": "0.0.77",
4
+ "description": "Grab any element in your app and give it to Cursor, Claude Code, or other AI coding agents.",
5
+ "keywords": [
6
+ "react",
7
+ "grab",
8
+ "react",
9
+ "agent",
10
+ "context"
11
+ ],
12
+ "homepage": "https://react-grab.com",
13
+ "bugs": {
14
+ "url": "https://github.com/aidenybai/react-grab/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/aidenybai/react-grab.git"
19
+ },
20
+ "license": "MIT",
21
+ "author": {
22
+ "name": "Aiden Bai",
23
+ "email": "aiden@million.dev"
24
+ },
25
+ "type": "module",
26
+ "exports": {
27
+ "./package.json": "./package.json",
28
+ ".": {
29
+ "import": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ },
33
+ "require": {
34
+ "types": "./dist/index.d.cts",
35
+ "default": "./dist/index.cjs"
36
+ }
37
+ },
38
+ "./core": {
39
+ "import": {
40
+ "types": "./dist/core.d.ts",
41
+ "default": "./dist/core.js"
42
+ },
43
+ "require": {
44
+ "types": "./dist/core.d.cts",
45
+ "default": "./dist/core.cjs"
46
+ }
47
+ },
48
+ "./dist/*": "./dist/*.js",
49
+ "./dist/*.js": "./dist/*.js",
50
+ "./dist/*.cjs": "./dist/*.cjs",
51
+ "./dist/*.mjs": "./dist/*.mjs"
52
+ },
53
+ "bin": {
54
+ "grab": "./dist/cli.cjs"
55
+ },
56
+ "main": "dist/index.js",
57
+ "module": "dist/index.js",
58
+ "browser": "dist/index.global.js",
59
+ "types": "dist/index.d.ts",
60
+ "files": [
61
+ "dist",
62
+ "package.json",
63
+ "README.md",
64
+ "LICENSE"
65
+ ],
66
+ "publishConfig": {
67
+ "access": "public"
68
+ },
69
+ "scripts": {
70
+ "build": "node scripts/build.js"
71
+ }
28
72
  }
package/lib/grab.js DELETED
@@ -1,103 +0,0 @@
1
- // Copyright (c) 2013 Andrew Luetgers, MIT License
2
-
3
- (function() {
4
-
5
- var root = this,
6
- _ = root._;
7
-
8
- if (!_ && "module" in root && module.exports) {
9
- root._ = _ = require("underscore");
10
- }
11
-
12
- if (!_) {
13
- throw new Error("grab.js requires underscore.js");
14
- }
15
-
16
- // cache regexes and strings to save some garbage
17
- var grabReQuo = /"|'/g,
18
- grabReOpBr = /\[/g,
19
- grabReClBr = /\]/g,
20
- emptyStr = "",
21
- period = ".";
22
-
23
- // handle blah.foo["stuff"][0].value or blah.foo.stuff.0.value
24
- // does not support property names containing periods or quotes or [ or ]
25
- function _grabStr(obj, path, alt, verbose) {
26
- path = path.replace(grabReQuo, emptyStr).replace(grabReOpBr, period).replace(grabReClBr, emptyStr).split(period);
27
- // results in ["blah", "foo", "stuff", 0, "value"]
28
- var val = obj, altVal;
29
- _.every(path, function(pathStr, idx) {
30
- console.log("val at", val, pathStr);
31
- val = val[pathStr]; // traverse deeper into the object
32
- if ((idx < path.length-1 && !val) || val === undefined || val === "" || val === null) {
33
- altVal = _.isFunction(alt) ? alt(obj, path, idx) : alt;
34
- return false;
35
- } else {
36
- return true;
37
- }
38
- });
39
-
40
- return verbose ? {val: val, altVal: altVal} : altVal || val;
41
- }
42
-
43
- /* handle multi selection on one object syntax
44
- var data = {blah: {foo: {test: ["hi"]}}};
45
- _.grab(data, {
46
- foo: "blah.foo",
47
- test: "blah.foo.test",
48
- missing: ["blah[0].test", "a default value"]
49
- });
50
- */
51
- function _grabObj(obj, path) {
52
- var res = {};
53
- _.each(path, function(val, key) {
54
- if (_.isArray(val)) {
55
- res[key] = _.grab(obj, val[0], val[1]); // handle default values as in missing above
56
- } else {
57
- res[key] = _.grab(obj, val);
58
- }
59
- });
60
-
61
- return res;
62
- }
63
-
64
- // handle an array of paths to try
65
- function _grabArr(obj, path, alt) {
66
- var val = {};
67
- _.all(path, function(_path) {
68
- val = _.grab(obj, _path, alt, true);
69
- return !val.val; // if no value continue on to the next path
70
- });
71
- console.log("_grabArr", val.val || val.altVal, val);
72
- return (val.val || val.val === 0 || val.val === false) ? val.val : val.altVal;
73
- }
74
-
75
-
76
- _.grab = function(obj, path, alt, verbose) {
77
-
78
- if (!obj) {return alt;}
79
-
80
- // handle blah.foo["stuff"][0].value or blah.foo.stuff.0
81
- if (typeof path === "string") {
82
- return _grabStr(obj, path, alt, verbose);
83
-
84
- // handle an array of paths to try
85
- } else if (_.isArray(path)) {
86
- return _grabArr(obj, path, alt, verbose);
87
-
88
- // handle multi selection on one object syntax
89
- } else if (_.isObject(path)) {
90
- return _grabObj(obj, path);
91
- }
92
-
93
- return alt;
94
- }
95
-
96
- if ("module" in root) {
97
- module.exports = {
98
- grab: _.grab,
99
- _: _
100
- };
101
- }
102
-
103
- }());
package/lib/grab.min.js DELETED
@@ -1,10 +0,0 @@
1
- // Copyright (c) 2013 Andrew Luetgers, MIT License
2
- (function(){var root=this,_=root._;if (!_ && "module" in root && module.exports) {root._ = _ = require("underscore");}
3
- if(!_){throw new Error("grab.js requires underscore.js");}
4
- var grabReQuo=/"|'/g,grabReOpBr=/\[/g,grabReClBr=/\]/g,emptyStr="",period=".";function _grabStr(obj,path,alt,verbose){path=path.replace(grabReQuo,emptyStr).replace(grabReOpBr,period).replace(grabReClBr,emptyStr).split(period);var val=obj,altVal;_.every(path,function(pathStr,idx){console.log("val at",val,pathStr);val=val[pathStr];if((idx<path.length-1&&!val)||val===undefined||val===""||val===null){altVal=_.isFunction(alt)?alt(obj,path,idx):alt;return false;}else{return true;}});return verbose?{val:val,altVal:altVal}:altVal||val;}
5
- function _grabObj(obj,path){var res={};_.each(path,function(val,key){if(_.isArray(val)){res[key]=_.grab(obj,val[0],val[1]);}else{res[key]=_.grab(obj,val);}});return res;}
6
- function _grabArr(obj,path,alt){var val={};_.all(path,function(_path){val=_.grab(obj,_path,alt,true);return!val.val;});console.log("_grabArr",val.val||val.altVal,val);return(val.val||val.val===0||val.val===false)?val.val:val.altVal;}
7
- _.grab=function(obj,path,alt,verbose){if(!obj){return alt;}
8
- if(typeof path==="string"){return _grabStr(obj,path,alt,verbose);}else if(_.isArray(path)){return _grabArr(obj,path,alt,verbose);}else if(_.isObject(path)){return _grabObj(obj,path);}
9
- return alt;}
10
- if("module"in root){module.exports={grab:_.grab,_:_};}}());